Add record Form, close and go to new record in other form

  • Thread starter Thread starter MC
  • Start date Start date
M

MC

I'm using a separate form to add a new client record. After the new client
record is added, I want to close the new client form and refresh the data in
another form which has all client records and go to the new client just
added.

I'm using the following code:

Dim lngCurrent As Long
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
lngCurrent = Me.ClientID.Value

Dim rst2 As ADODB.Recordset
Set rst2 = Form_frmManage.Form.Recordset
Form_frmManage.Refresh

rst2.Find "clientid=" & lngCurrent, , adSearchForward, 1
DoCmd.Close acForm, "frmNewClient"

Problem seems to be that the Form_frmManage hasn't finished refreshing
before the Find is run, therefore the Find cannot find the new record.

Is there a way to wait until the refresh is completed, then run the Find?

Any help appreciated
 
Requerying the form may work.
DoEvents might cope with the lag.

But this should be better:
Dim frm As Form

Me.Dirty = False

Set frm = Forms!frmManage
frm.Requery
With frm.RecordsetClone
.FindFirst "ClientID = " & Me.ClientID
If .NoMatch Then
MsgBox "Not found in other form."
Else
frm.Bookmark = .Bookmark
End If
End With

Set frm = Nothing
DoCmd.Close acForm, Me.Name
 
For

If .NoMatch Then

....I get runtime error: "Object doesn't support this property or method"

and...

frm.Bookmark = .Bookmark

....I get runtime error: "Either BOF or EOF is true..."
 
Back
Top