Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2003
    Location
    Los Angeles
    Posts
    6

    Unanswered: Bring up record in form

    OK, I have a form that is supposed to bring up a record if it is a duplicate, this is my code but whenever I click on yes to bring up the record it doesn't do anything, the textboxes in the form remain blank. Can anyone tell me if there are any additional steps to do??
    Here's the code:

    Dim varEmpNum As Variant

    varEmpNum = DLookup("FirstName", "Contacts", "Employee=""" & Me.Employee & """")
    If Not IsNull(varEmpNum) Then
    'the employee already exists
    If MsgBox("An Employee with this name already exists, would you like to go to this record?", vbYesNo) = vbYes Then
    'cancel update
    Cancel = True
    'undo the changes to this record
    Me.Undo
    'go to matching record
    With Me.RecordsetClone
    .FindFirst "Employee=""" & Me.Employee & """"
    If Not .NoMatch Then
    Me.Bookmark = .Bookmark
    End If
    End With
    End If
    End If

  2. #2
    Join Date
    Jul 2003
    Location
    Michigan
    Posts
    1,941
    When you run

    Me.Undo

    You are setting the Me.Employee field to Null

    Therefore

    .FindFirst "Employee=""" & Me.Employee & """"

    Is searching for Employee = Null

    Add:

    Dim strEmployee as string (or whatever data type your using)

    before you cancel the update, add

    strEmployee = Me.Employee

    Then replace

    .FindFirst "Employee=""" & Me.Employee & """"

    with
    .FindFirst "Employee=""" & strEmployee & """"
    Inspiration Through Fermentation

  3. #3
    Join Date
    Aug 2003
    Location
    Los Angeles
    Posts
    6
    works like a charm, thank you very much!

    Originally posted by RedNeckGeek
    When you run

    Me.Undo

    You are setting the Me.Employee field to Null

    Therefore

    .FindFirst "Employee=""" & Me.Employee & """"

    Is searching for Employee = Null

    Add:

    Dim strEmployee as string (or whatever data type your using)

    before you cancel the update, add

    strEmployee = Me.Employee

    Then replace

    .FindFirst "Employee=""" & Me.Employee & """"

    with
    .FindFirst "Employee=""" & strEmployee & """"

Posting Permissions

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