What is wrong with code?

D

Dave Elliott

It should open the form BlankChecks and show whatever record(s) are in combo
box.
The combo box is located on a form named frmAutoPayrollReport
Thanks,

Dave

stDocName = "BlankChecks"
DoCmd.OpenForm "BlankChecks", , , [Customers] = " & Me.Combo187"
 
K

Kevin Sprinkel

1) Since you've intelligently assigned your formname to a
variable, making the code more portable and editable, you
can simply refer to the variable in the OpenForm call
rather than the formname explicitly:

DoCmd.OpenForm stDocName ...etc.

It would still work, however, as is.

2) The Where condition is a string, so any literals need
to be enclosed in quotes.

3) It would be better to extend the portability concept by
using a variable for the WHERE condition as well, and add
some error handling.

Replace the capitalized references with your appropriate
names.

Private Sub YOURCOMMANDBUTTONNAME_Click()
On Error Go To Err_YOURFORMNAME_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "BlankChecks"
stLinkCriteria = "[Customers]=" & Me![Combo187]
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_YOURFORMNAME_Click:
Exit Sub

Err_YOURFORMNAME_Click:
MsgBox Err.Description
Resume Exit_YOURFORMNAME_Click

End Sub

HTH
Kevin Sprinkel
 
J

Jim Allensworth

It should open the form BlankChecks and show whatever record(s) are in combo
box.
The combo box is located on a form named frmAutoPayrollReport
Thanks,

Dave

stDocName = "BlankChecks"
DoCmd.OpenForm "BlankChecks", , , [Customers] = " & Me.Combo187"
Dave, the problem is with the Where argument of the method. The quotes
go like ...

DoCmd.OpenForm "BlankChecks", , , "[Customers] = " & Me.Combo187

Note that there is none around your control reference.

- Jim
 
R

Reggie

Dave, If Customers is a:

'number field do this:
DoCmd.OpenForm "BlankChecks", , , "[Customers] = " & Me.Combo187

'text field do this:
DoCmd.OpenForm "BlankChecks", , , "[Customers] = '" & Me.Combo187 & "'"

Should do it.
--
Reggie

----------
Dave Elliott said:
It should open the form BlankChecks and show whatever record(s) are in combo
box.
The combo box is located on a form named frmAutoPayrollReport
Thanks,

Dave

stDocName = "BlankChecks"
DoCmd.OpenForm "BlankChecks", , , [Customers] = " & Me.Combo187"
 
D

Dave Elliott

I get this error when I run the code: Nations Rent being the Customer I
chose from the Combo187 List
Syntax error (missing operator) in query expression '[Customers] = Nations
Rent'.


Jim Allensworth said:
It should open the form BlankChecks and show whatever record(s) are in combo
box.
The combo box is located on a form named frmAutoPayrollReport
Thanks,

Dave

stDocName = "BlankChecks"
DoCmd.OpenForm "BlankChecks", , , [Customers] = " & Me.Combo187"
Dave, the problem is with the Where argument of the method. The quotes
go like ...

DoCmd.OpenForm "BlankChecks", , , "[Customers] = " & Me.Combo187

Note that there is none around your control reference.

- Jim
 
K

Ken Snell

Assuming that Customers is a text-formatted field, you need to delimit the
value from the combo box with ' characters:

DoCmd.OpenForm "BlankChecks", , , "[Customers] = '" & Me.Combo187 & "'"

--

Ken Snell
<MS ACCESS MVP>



Dave Elliott said:
I get this error when I run the code: Nations Rent being the Customer I
chose from the Combo187 List
Syntax error (missing operator) in query expression '[Customers] = Nations
Rent'.


Jim Allensworth said:
It should open the form BlankChecks and show whatever record(s) are in combo
box.
The combo box is located on a form named frmAutoPayrollReport
Thanks,

Dave

stDocName = "BlankChecks"
DoCmd.OpenForm "BlankChecks", , , [Customers] = " & Me.Combo187"
Dave, the problem is with the Where argument of the method. The quotes
go like ...

DoCmd.OpenForm "BlankChecks", , , "[Customers] = " & Me.Combo187

Note that there is none around your control reference.

- Jim
 
D

Dave Elliott

Thanks for Your Help, Reggie, Jim and Kevin

Dave

The &"" did the trick
Reggie said:
Dave, If Customers is a:

'number field do this:
DoCmd.OpenForm "BlankChecks", , , "[Customers] = " & Me.Combo187

'text field do this:
DoCmd.OpenForm "BlankChecks", , , "[Customers] = '" & Me.Combo187 & "'"

Should do it.
--
Reggie

----------
Dave Elliott said:
It should open the form BlankChecks and show whatever record(s) are in combo
box.
The combo box is located on a form named frmAutoPayrollReport
Thanks,

Dave

stDocName = "BlankChecks"
DoCmd.OpenForm "BlankChecks", , , [Customers] = " & Me.Combo187"
 

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