+ Reply to Thread
Results 1 to 2 of 2

Thread: Access - VBA - If record Exsists, find and ask to Edit

  1. #1
    Registered User
    Join Date
    08-06-2007
    Posts
    99

    Access - VBA - If record Exsists, find and ask to Edit

    Hello,

    I'm looking for some logic on my Access form. Currently, I have "email" set as a primary key so when someone enters a new email address it pops up saying the record already exists. I have a simple error check VBA message for this currently which brings up the message box.

    My problem is from that point on, even if you blank out the email field it keeps giving you an error until you enter in something unique. And I have to manually remove it from the table.

    I would like to expand the logic to point out if the record already exists based on the email field, and if so, ask the user if they would like to edit the the information. If Yes is selected, have it bring up the record they tried to enter inside the forum so they can change name or address information.

    If No is selected, then do nothing and allow the user to enter a different email if desired.

    I tried writing this code - but it doesn't really work:

    Private Sub Command18_Click()
    
    On Error GoTo Err_chk
    
    DoCmd.GoToRecord , , acNewRec
    
    Err_chk:
    If Err.Number = 2105 Or 3022 Then
    If MsgBox("Record already exsists!" & vbCr & vbCr & "Do you wish to update it?", vbYesNo) = vbYes Then
    
    DoCmd.RunCommand acCmdDeleteRecord
    DoCmd.FindRecord Text0.Value, , True, , True, acCurrent
    Else
    DoCmd.RunCommand acCmdDeleteRecord
    End If
    End If
    
    End Function
    Thanks in advance!
    Last edited by adgjqetuo; 03-23-2011 at 08:55 PM.

  2. #2
    Registered User
    Join Date
    08-06-2007
    Posts
    99

    Re: Access - VBA - If record Exsists, find and ask to Edit

    Anyone?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.2.0