trying to go to new record when form is open

G

Guest

The following code is an event procedure for form open. I don't know if it
is correct or not, but I am trying to open the client table when information
in a related table is being added and the client doesn't exist. If the
client exists, the client form is opened so that the user can add the client.
I got that to work ok, but the form was on a client, I wanted it to go to a
new record so that the user doesn't have to. The code below generates an
error when the docmd is run. the error is "the object "Clients" isn't open.
The clients table is the recordsource for this form. What am I doing wrong?

Private Sub Form_Open(Cancel As Integer)
Dim strOpenCondition As String
strOpenCondition = Forms![frm lcm clients].OpenArgs
Select Case strOpenCondition
Case "GoToNew"
DoCmd.GoToRecord acDataTable, "Clients", acNewRec
End Select
End Sub
 
D

Dirk Goldgar

terry said:
The following code is an event procedure for form open. I don't know
if it is correct or not, but I am trying to open the client table
when information in a related table is being added and the client
doesn't exist. If the client exists, the client form is opened so
that the user can add the client. I got that to work ok, but the
form was on a client, I wanted it to go to a new record so that the
user doesn't have to. The code below generates an error when the
docmd is run. the error is "the object "Clients" isn't open. The
clients table is the recordsource for this form. What am I doing
wrong?

Private Sub Form_Open(Cancel As Integer)
Dim strOpenCondition As String
strOpenCondition = Forms![frm lcm clients].OpenArgs
Select Case strOpenCondition
Case "GoToNew"
DoCmd.GoToRecord acDataTable, "Clients", acNewRec
End Select
End Sub

How about

' ...
Case "GoToNew"
RunCommand acCmdRecordsGoToNew
 
D

Dirk Goldgar

terry said:
The following code is an event procedure for form open. I don't know
if it is correct or not, but I am trying to open the client table
when information in a related table is being added and the client
doesn't exist. If the client exists, the client form is opened so
that the user can add the client. I got that to work ok, but the
form was on a client, I wanted it to go to a new record so that the
user doesn't have to. The code below generates an error when the
docmd is run. the error is "the object "Clients" isn't open. The
clients table is the recordsource for this form. What am I doing
wrong?

Private Sub Form_Open(Cancel As Integer)
Dim strOpenCondition As String
strOpenCondition = Forms![frm lcm clients].OpenArgs
Select Case strOpenCondition
Case "GoToNew"
DoCmd.GoToRecord acDataTable, "Clients", acNewRec
End Select
End Sub

Another possibility is just to open the form in data-entry mode , by
specifying acFormAdd for the DataMode argument of the DoCmd.OpenFormn
method.
 
G

Guest

Thanks, that did it.

Dirk Goldgar said:
terry said:
The following code is an event procedure for form open. I don't know
if it is correct or not, but I am trying to open the client table
when information in a related table is being added and the client
doesn't exist. If the client exists, the client form is opened so
that the user can add the client. I got that to work ok, but the
form was on a client, I wanted it to go to a new record so that the
user doesn't have to. The code below generates an error when the
docmd is run. the error is "the object "Clients" isn't open. The
clients table is the recordsource for this form. What am I doing
wrong?

Private Sub Form_Open(Cancel As Integer)
Dim strOpenCondition As String
strOpenCondition = Forms![frm lcm clients].OpenArgs
Select Case strOpenCondition
Case "GoToNew"
DoCmd.GoToRecord acDataTable, "Clients", acNewRec
End Select
End Sub

How about

' ...
Case "GoToNew"
RunCommand acCmdRecordsGoToNew


--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 

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