Results 1 to 9 of 9

Thread: code for vba

  1. #1
    Join Date
    Nov 2003
    Location
    england
    Posts
    95

    Unanswered: code for vba

    Guys!

    I was just wondering what the code was that displays an alert when u go to amend, delete a record etc....like...'r u sure' somin along those lines...how and where would it go in the vba???

    cheers lucy xxx

  2. #2
    Join Date
    Feb 2004
    Posts
    142
    Look in the form event Before_Update and display a message box like -

    Form_BeforeUpdate(Cancel as integer)
    if vbno = msgbox("Are you Sure.",vbyesno + vbquestion,"Update Warning") then
    cancel = true 'this blocks update
    end if
    KC

  3. #3
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    Are you talking about the message that says:

    You are about to delete x records are you sure?

    and

    You are about to append x records are you sure?


    If so these are generated by Access. You can turn them off if you want.

    Otherwise you are talking about a custom message and that depends on when you want the message to appear. Example, in a form, before you delete a record. In this case you would want to look at the On Delete event of the form. It's hard to give you 'code' for this, because typically you want to customize it to give the user more information that the generic Access messages. So the text, when and where are all customizable.

  4. #4
    Join Date
    Nov 2003
    Location
    england
    Posts
    95
    Private Sub DeleteSupplier_Click()
    On Error GoTo Err_DeleteSupplier_Click


    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70



    Exit_DeleteSupplier_Click:
    Exit Sub

    Err_DeleteSupplier_Click:
    MsgBox Err.Description
    Resume Exit_DeleteSupplier_Click

    End Sub

    this is the code but im not sure where im supposed to put mine???

  5. #5
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    Try this:

    Private Sub DeleteSupplier_Click()
    On Error GoTo Err_DeleteSupplier_Click

    Dim intResponse as Integer

    intResponse = MsgBox("This is your message",,vbQuestion,"OK To Delete?")

    if intResponse = vbYes Then
    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
    end if


    Exit_DeleteSupplier_Click:
    Exit Sub

    Err_DeleteSupplier_Click:
    MsgBox Err.Description
    Resume Exit_DeleteSupplier_Click

    End Sub

  6. #6
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    Oops. Too many commas change

    intResponse = MsgBox("This is your message",,vbQuestion,"OK To Delete?")

    to

    intResponse = MsgBox("This is your message",vbQuestion,"OK To Delete?")

    I removed the comma before vbQuestion.

  7. #7
    Join Date
    Nov 2003
    Location
    england
    Posts
    95
    Cheers! worked a treat! ome more thing...it only gives you the option of yes...instead of the access way when it said yes....no ???

  8. #8
    Join Date
    Feb 2004
    Location
    Chicago, IL
    Posts
    1,312
    Change:

    vbQuestion

    To:

    vbQuestion + vbYesNo

  9. #9
    Join Date
    Nov 2003
    Location
    england
    Posts
    95

    Talking

    Thank you! much apriciated!!
    ^^^^^^^
    sorry if spelt wrong!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •