T
The Mecca
When I close my form I have a code to save to a table, the last record I
looked at - that one works fine- but when I want to open the form again. It
doesn't open to that record. help please?
My code is:
TO SAVE RECORD=
Private Sub Form_Load()
Dim varID As Variant
varID = DLookup("[Value]", "tblSys", "[Variable] ='Account NumberLast'")
If IsNumeric(varID) Then
With Me.RecordsetClone
.FindNext "[Account Number] = " & varID
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With
End If
End Sub
TO OPEN SAME RECORD=
Private Sub Form_Unload(Cancel As Integer)
Dim rs As DAO.Recordset
If Not IsNull(Me.[Account Number]) Then
Set rs = CurrentDb().OpenRecordset("tblSys", dbOpenDynaset)
With rs
.FindFirst "[Variable] = 'Account NumberLast'"
If .NoMatch Then
.AddNew 'Create the entry if not found.
![Variable] = "CustomerIDLast"
![Value] = Me.[Account Number]
![Description] = "Last Account Number, for form " & Me.Name
.Update
Else
.Edit 'Save the current record's primary key.
![Value] = Me.[Account Number]
.Update
End If
End With
rs.Close
End If
Set rs = Nothing
End Sub
looked at - that one works fine- but when I want to open the form again. It
doesn't open to that record. help please?
My code is:
TO SAVE RECORD=
Private Sub Form_Load()
Dim varID As Variant
varID = DLookup("[Value]", "tblSys", "[Variable] ='Account NumberLast'")
If IsNumeric(varID) Then
With Me.RecordsetClone
.FindNext "[Account Number] = " & varID
If Not .NoMatch Then
Me.Bookmark = .Bookmark
End If
End With
End If
End Sub
TO OPEN SAME RECORD=
Private Sub Form_Unload(Cancel As Integer)
Dim rs As DAO.Recordset
If Not IsNull(Me.[Account Number]) Then
Set rs = CurrentDb().OpenRecordset("tblSys", dbOpenDynaset)
With rs
.FindFirst "[Variable] = 'Account NumberLast'"
If .NoMatch Then
.AddNew 'Create the entry if not found.
![Variable] = "CustomerIDLast"
![Value] = Me.[Account Number]
![Description] = "Last Account Number, for form " & Me.Name
.Update
Else
.Edit 'Save the current record's primary key.
![Value] = Me.[Account Number]
.Update
End If
End With
rs.Close
End If
Set rs = Nothing
End Sub