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

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
 
A

Allen Browne

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
 
M

mc

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..."
 
A

Allen Browne

Perhaps it's an ADO recordset. Instead of FindFirst, MoveFirst, and then
Find.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top