command button code question

  • Thread starter Slez via AccessMonster.com
  • Start date
S

Slez via AccessMonster.com

I have a command button, cmdAddClient, on a mainform, frmClientMain. I would
like to make it so when users click it, it takes you to the new record in a
subform called frmClientList.

I tried the following code, but get an error message that I have the wrong
number of arguments. I'm quite certain the problem lies in my "DoCmd..."
line of code. Can anyone help with the code that is required to accomplish
this? Thanks in advance!!

Private Sub cmdAddClient_Click()
On Error GoTo Err_cmdAddClient_Click

Dim stDocName As String

stDocName = "frmClientList"
DoCmd.GoToRecord , , acNewRec, stDocName

Exit_cmdAddClient_Click:
Exit Sub

Err_cmdAddClient_Click:
MsgBox Err.Description
Resume Exit_cmdAddClient_Click

End Sub
 
A

antman142

Hello, You have the name of the form listed in the Offset argument.

by definition the GoToRecord Method looks like this:
expression.GoToRecord(ObjectType, ObjectName, Record, Offset)

So your code should look like one of the samples below:

Docmd.GoToRecord acDataForm, "frmClientList",acNewRec
or
Dim stDocName As String

stDocName = "frmClientList"
DoCmd.GoToRecord acDataForm, stDocName, acNewRec

for more explanation go to the Help files in Access and search for GoToRecord
Method.

hope this helps. :)

Antman
 

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