Help with VBA code to run update query and open form.

R

Rex Deckard

I am having a problem with the below bit of code, each time I try and
run it, I get an: Wrong number of arguments or invalid property
assignment (Error 450)

The code is as seen below. I am not sure what I am missing, but I bet
it is really simply.

All fields are numeric that are referenced in the code.

-update suffix is a macro

Private Sub Command4_Click()
On Error GoTo Err_Command4_Click

Dim stDocName As String
Dim stDocName1 As String
Dim stLinkCriteria As String
Dim stLinkCriteria1 As String

'DoCmd.RunCommand acCmdSaveRecord

stDocName = "update suffix"
stLinkCriteria = "[bill_of_lading]=" & Me![bill_of_lading]
DoCmd.RunMacro "update suffix", , , stLinkCriteria
'DoCmd.RunMacro stDocName, , , stLinkCriteria


stDocName1 = "bol_entryreprint"
stLinkCriteria1 = "[BOL]=" & Me![BOL]
DoCmd.OpenForm stDocName1, , , stLinkCriteria1


Exit_Command4_Click:
Exit Sub

Err_Command4_Click:
MsgBox Err.Description
Resume Exit_Command4_Click

End Sub
 
S

SteveS

Rex,

The error is caused by the line
DoCmd.RunMacro "update suffix", , , stLinkCriteria


The DoCmd.RunMacro syntax is:

DoCmd.RunMacro macroname[, repeatcount][, repeatexpression]

There is one too many commas and the stLinkCriteria won't limit records like you
want. The explanation for the [, repeatexpression] argument is (from Help):

"repeatexpression: A numeric expression that's evaluated each time the macro
runs. When it evaluates to False (0), the macro stops running. "


If you are using A2K (I'm not sure about A97), there is a wizard to convert the
macro to VBA code. Macros are (my opinion) very limiting and (in almost all
cases) should be avoided.


HTH
--
Steve
--------------------------------
"Veni, Vidi, Velcro"
(I came, I saw, I stuck around.)


Rex said:
I am having a problem with the below bit of code, each time I try and
run it, I get an: Wrong number of arguments or invalid property
assignment (Error 450)

The code is as seen below. I am not sure what I am missing, but I bet
it is really simply.

All fields are numeric that are referenced in the code.

-update suffix is a macro

Private Sub Command4_Click()
On Error GoTo Err_Command4_Click

Dim stDocName As String
Dim stDocName1 As String
Dim stLinkCriteria As String
Dim stLinkCriteria1 As String

'DoCmd.RunCommand acCmdSaveRecord

stDocName = "update suffix"
stLinkCriteria = "[bill_of_lading]=" & Me![bill_of_lading]
DoCmd.RunMacro "update suffix", , , stLinkCriteria
'DoCmd.RunMacro stDocName, , , stLinkCriteria


stDocName1 = "bol_entryreprint"
stLinkCriteria1 = "[BOL]=" & Me![BOL]
DoCmd.OpenForm stDocName1, , , stLinkCriteria1


Exit_Command4_Click:
Exit Sub

Err_Command4_Click:
MsgBox Err.Description
Resume Exit_Command4_Click

End Sub
 
R

Rex Deckard

Thanks, I redid the macro inside of the procedure and did the update
query thru a sql statement rather then an update query.

Works now.

Thanks again.


SteveS wrote in message news: said:
Rex,

The error is caused by the line
DoCmd.RunMacro "update suffix", , , stLinkCriteria


The DoCmd.RunMacro syntax is:

DoCmd.RunMacro macroname[, repeatcount][, repeatexpression]

There is one too many commas and the stLinkCriteria won't limit records like you
want. The explanation for the [, repeatexpression] argument is (from Help):

"repeatexpression: A numeric expression that's evaluated each time the macro
runs. When it evaluates to False (0), the macro stops running. "


If you are using A2K (I'm not sure about A97), there is a wizard to convert the
macro to VBA code. Macros are (my opinion) very limiting and (in almost all
cases) should be avoided.


HTH
 

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