Testing Bookmark for not found

JHMarshIII

Registered User.
Local time
Today, 11:47
Joined
Feb 8, 2002
Messages
19
Iv'e got a form that uses a key (UnitKey) to look up the record if the key is found. If found I want the focus to move to a particular control, if not found I want the focus to move to another inquiry control. I think my code is wrong when I try to test the result for the If/Then statement. Here is the code:

Private Sub UnitKeyAddr_AfterUpdate()

' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[UnitAddr] = '" & Me![UnitKeyAddr] & "'"
Me.Bookmark = rs.Bookmark
'Tests bookmark for hit
If IsNull(Me![UnitKeyAddr]) Then
' Clears UnitKey
Let Me![UnitKeyAddr] = ""
' Changes Focus to alphalookup
DoCmd.GoToControl "alphalookup"
Else
' Clears UnitKey
Let Me![UnitKeyAddr] = ""
' Changes Focus to Salutation
DoCmd.GoToControl "Salut"
End If
End Sub

In both a true and false case the focus is set to "Salut" so I think I am asking the wrong question in the line:

If IsNull(Me![UnitKeyAddr]) Then
 
Check this one out
Code:
' code needs a reference to the dao object library
Private Sub UnitKeyAddr_AfterUpdate()
  ' Find the first record that matches exactly
  ' the contents of control [UnitKeyAddr]
  With Me.RecordsetClone
    .FindFirst "[UnitAddr] = '" & Me![UnitKeyAddr] & "'"
    If Not .NoMatch Then
      ' there's a match
      ' synchronize the form with it's recordsetclone's bookmark
      Me.Bookmark = .Bookmark
      ' Set focus on the Salut control
      Me("Salut").SetFocus
    Else
      ' no match
      ' move the focus to the alphalookup control
      Me("alphalookup").SetFocus
    End If
  End With
End Sub
 
Thanks

Thank you, the code works great.
 

Users who are viewing this thread

Back
Top Bottom