DoCmd.FindRecord

  • Thread starter Thread starter Mary
  • Start date Start date
M

Mary

Hi all.

I don't understand FindRecord, I guess.

My main client form is always open to a client. I popup a
form (from any client that has form focus) to enter data
for a new client and, thus, add them as a client (they
had not existed). Upon closing that new client entry form
the focus is back on the main client form as I departed
to enter the new client, and I want it to be on the newly
created client's record.

It appears that on closing the popup entry form I can use
DoCmd.FindRecord, but I cannot figure it out. My new
client's ID is a control on the popup form named
cboClientID and is for the table field ClientID. ClientID
is primary key.

Can anyone offer a solution that does not require an MIS
in Access? I am an amateur.


Thanks.
Mary
 
Use DoCmd.GoToControl to set the focus to the field you are searching
(cboClientID?) and then use FindRecord.
 
Thanks. Here's what I have now.

Forms![frm1VE Client].Requery
DoCmd.GoToControl (Me.ClientID)
DoCmd.FindRecord (Me.ClientID)
DoCmd.Close

With this I create a form and message is "There is no
field named 'AAA999' in the current record. I got that
before the above requery and thought that would solve it.

This code is of frm1DE Client (popup) and I am trying to
get the newly created record to display on frm1VE Client
(which is where I get the popup.)

Can you see what's wrong with my coding?

Any help is appreciated.

Thanks,
Mary
 
Take a look at the OpenForm method. The code would look something like this:

DoCmd.OpenForm "frmClient", , , "[ClientID] = '" & Me!txtClientID & "'"




Mary said:
Thanks. Here's what I have now.

Forms![frm1VE Client].Requery
DoCmd.GoToControl (Me.ClientID)
DoCmd.FindRecord (Me.ClientID)
DoCmd.Close

With this I create a form and message is "There is no
field named 'AAA999' in the current record. I got that
before the above requery and thought that would solve it.

This code is of frm1DE Client (popup) and I am trying to
get the newly created record to display on frm1VE Client
(which is where I get the popup.)

Can you see what's wrong with my coding?

Any help is appreciated.

Thanks,
Mary
-----Original Message-----
Use DoCmd.GoToControl to set the focus to the field you are searching
(cboClientID?) and then use FindRecord.


.
 
Put the following code in the Click event of the button you have to open the
pop-up form:
Docmd.OpenForm "NameOfPopupForm",,,,,acDialog
If IsNull(Forms!NameOfPopupForm!ClientID) Then
Msgbox "A new client was not entered!"
Else
Dim Rst As DAO.Recordset
Set Rst = Me.RecordsetClone
Rst.FindFirst "[ClientID] = " & Forms!NameOfPopupForm!ClientID
Me.BookMark = Rst.BookMark
Rst.Close
Set Rst = Nothing
End If
DoCmd.Close acForm, "NameOfPopupForm"

In your popup form, change the code you have for the Close button to this:
DoCmd.RunCommand acCmdSaveRecord
Me.Visible = False

It works like this:
You click the button on the main client form to add a new client. The popup
form opens and you enter the new client. You click the Close button on the
popup form, the new client is saved and the popup form disappears (becomes
not visible). The main client form then jumps to the new client record and
closes the popup form.
 
Back
Top