VBAcode question

  • Thread starter Thread starter Junior
  • Start date Start date
J

Junior

Using the following code to add a record to tblApp - it works -
but the recordsetclone section returns the form to the first record in
tblApp and not the one just saved?
what am i doing wrong?
Dim db As Database
Dim rsApp As DAO.Recordset
Set db = CurrentDb
Set rsApp = db.OpenRecordset("tblApp", DB_OPEN_DYNASET)
rsApp.FindFirst "SSN = " & Chr(34) & strApSSN & Chr(34)
If rsApp.NoMatch Then

rsApp.AddNew
rsApp("SSN") = (strApSSN) 'strApSSN public variable last SSN entered
into TblMstr
rsApp("AppPosition") = "xxx"
rsApp("ApplicationDate") = VBA.Date
rsApp.Update
rsApp.Close ' Close table.

Set rsApp = Nothing

RunCommand acCmdSaveRecord
Me.txtSSN.Requery
If Not IsNull(Me!txtSSN) And Me.txtSSN <> 9999999 Then
Me.RecordsetClone.FindFirst "[AppID] =" & Me![txtSSN]
Me.Bookmark = Me.RecordsetClone.Bookmark
End If
End If
 
Your code requeries the text box.
After inserting a record into the table programmatically, you need to
requery the form:
Me.Requery

With your code the way it is, if you tested the NoMatch property of the
form's RecordsetClone after the FindFirst, you would find it to be true.
 
Allen - thanks
Allen Browne said:
Your code requeries the text box.
After inserting a record into the table programmatically, you need to
requery the form:
Me.Requery

With your code the way it is, if you tested the NoMatch property of the
form's RecordsetClone after the FindFirst, you would find it to be true.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Junior said:
Using the following code to add a record to tblApp - it works -
but the recordsetclone section returns the form to the first record in
tblApp and not the one just saved?
what am i doing wrong?
Dim db As Database
Dim rsApp As DAO.Recordset
Set db = CurrentDb
Set rsApp = db.OpenRecordset("tblApp", DB_OPEN_DYNASET)
rsApp.FindFirst "SSN = " & Chr(34) & strApSSN & Chr(34)
If rsApp.NoMatch Then

rsApp.AddNew
rsApp("SSN") = (strApSSN) 'strApSSN public variable last SSN entered
into TblMstr
rsApp("AppPosition") = "xxx"
rsApp("ApplicationDate") = VBA.Date
rsApp.Update
rsApp.Close ' Close table.

Set rsApp = Nothing

RunCommand acCmdSaveRecord
Me.txtSSN.Requery
If Not IsNull(Me!txtSSN) And Me.txtSSN <> 9999999 Then
Me.RecordsetClone.FindFirst "[AppID] =" & Me![txtSSN]
Me.Bookmark = Me.RecordsetClone.Bookmark
End If
End If
 
Back
Top