Return to the same record next time form is opened

Harry Shmedlap

Registered User.
Local time
Today, 23:36
Joined
Aug 9, 2005
Messages
51
The above great article on the Allen Browne site has one problem. I don't know if someone has posted it before but if the lookup is text rather than numeric then search is not found.
Here is a modified version:

Sub Form_Load()
Dim varID As Variant
Dim searchString As String
varID = DLookup("Value", "tblSys", "[Variable] = 'CustomerIDLast'")
If IsNumeric(varID) Then
searchString = "[CustomerID] = " & varID
Else
searchString = "[CustomerID] = " & "'" & varID & "'"
End If
With Me.RecordsetClone
.FindFirst searchString
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With
End Sub
 
why not change it to your specific requirement.
if you require a numneric lookup then remove the single quotes.
 
why not change it to your specific requirement.
if you require a numneric lookup then remove the single quotes.

Actually, Mr. Shmedlap neglected to mention the fact that Allen's code includes the line that appears in bold below:

Sub Form_Load()
Dim varID As Variant
Dim strDelim As String
'Note: If CustomerID field is a Text field (not a Number field), remove single quote at start of next line.
'strDelim = """"
 
Last edited:
Sub Form_Load()
Dim varID As Variant
Dim strDelim As String
'Note: If CustomerID field is a Text field (not a Number field), remove single quote at start of next line.
'strDelim = """"


varID = DLookup("Value", "tblSys", "[Variable] = 'CustomerIDLast'")
If IsNumeric(varID) Then
With Me.RecordsetClone
.FindFirst "[CustomerID] = " & strDelim & varID & strDelim
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With
End If
End Sub

http://allenbrowne.com/ser-18.html
 
Last edited:

Users who are viewing this thread

Back
Top Bottom