Please help to check code

  • Thread starter Thread starter Richard
  • Start date Start date
R

Richard

Hi

I keep getting the error 2498, "An expression you entered is the wrong data
type for one of the arguments"

Can you please check and see which is the worng argument?

Thanks in advance
Richard

Code as follows:
Dim RptInst As New Report_RptConsoRate


If IsNull([consocode]) Then
MsgBox "Please choose report to print", , "Choose client"
Me.consocode.SetFocus
Else
Dim criteria As String

criteria = "[conso-code]= forms![conso check]!consocode " & _
"AND consoid= forms![conso check]!txtconsoid " & _
"AND Workshopdate Between Forms![conso check]!beginningdate
" & _
"And Forms![conso check]!enddate"

DoCmd.OpenReport RptInst, acViewPreview, , criteria
DoCmd.RunCommand acCmdPrint
DoCmd.Close
--
 
You must evaluate the parameters outside the string and concatenate the
actual values, not the references. Try this:


criteria = "[conso-code]= " & forms![conso check]!consocode & _
" AND consoid= "forms![conso check]!txtconsoid & _
" AND Workshopdate Between " & Forms![conso
check]!beginningdate & _
" And " & Forms![conso check]!enddate

Note that the above is written assuming that all parameters are providing
numbers (not text or dates). If you are using text or dates, you need to
insert ' on either side of a text string, and # on either side of a date
value (date value must be in mm/dd/yyyy format).
 
Hi Ken

Thanks for the tip. I used this for preview and it works:

Dim stDocName As String
stDocName = "rptConsoRate"

If IsNull([consocode]) Then
MsgBox "Please choose report to view", , "Choose report"
Me.consocode.SetFocus
Else

Dim criteria As String

criteria = "[conso-code]= forms![conso check]!consocode " & _
"AND consoid= forms![conso check]!txtconsoid " & _
"AND Workshopdate Between Forms![conso check]!beginningdate
" & _
"And Forms![conso check]!enddate"

DoCmd.OpenReport stDocName, acPreview, , criteria

But when I dim it as a new report the error occurs. Anyway, I tried using
the criteria you suggested and the error occured still:

criteria = "[conso-code]= " & """ & Forms![conso check]!consocode & """ & _
" AND consoid= " & Forms![conso check]!txtConsoId & _
" AND Workshopdate Between " & "#" & Forms![conso
check]!Beginningdate & "#" & _
" And " & "#" & Forms![conso check]!enddate & "#"

Any clues? Thanks again

Richard

--


Ken Snell said:
You must evaluate the parameters outside the string and concatenate the
actual values, not the references. Try this:


criteria = "[conso-code]= " & forms![conso check]!consocode & _
" AND consoid= "forms![conso check]!txtconsoid & _
" AND Workshopdate Between " & Forms![conso
check]!beginningdate & _
" And " & Forms![conso check]!enddate

Note that the above is written assuming that all parameters are providing
numbers (not text or dates). If you are using text or dates, you need to
insert ' on either side of a text string, and # on either side of a date
value (date value must be in mm/dd/yyyy format).

--
Ken Snell
<MS ACCESS MVP>

Richard said:
Hi

I keep getting the error 2498, "An expression you entered is the wrong data
type for one of the arguments"

Can you please check and see which is the worng argument?

Thanks in advance
Richard

Code as follows:
Dim RptInst As New Report_RptConsoRate


If IsNull([consocode]) Then
MsgBox "Please choose report to print", , "Choose client"
Me.consocode.SetFocus
Else
Dim criteria As String

criteria = "[conso-code]= forms![conso check]!consocode " & _
"AND consoid= forms![conso check]!txtconsoid " & _
"AND Workshopdate Between Forms![conso check]!beginningdate
" & _
"And Forms![conso check]!enddate"

DoCmd.OpenReport RptInst, acViewPreview, , criteria
DoCmd.RunCommand acCmdPrint
DoCmd.Close
 
When you "dim" what as a new report? I don't understand this terminology.

Show this code.

--
Ken Snell
<MS ACCESS MVP>

Richard said:
Hi Ken

Thanks for the tip. I used this for preview and it works:

Dim stDocName As String
stDocName = "rptConsoRate"

If IsNull([consocode]) Then
MsgBox "Please choose report to view", , "Choose report"
Me.consocode.SetFocus
Else

Dim criteria As String

criteria = "[conso-code]= forms![conso check]!consocode " & _
"AND consoid= forms![conso check]!txtconsoid " & _
"AND Workshopdate Between Forms![conso check]!beginningdate
" & _
"And Forms![conso check]!enddate"

DoCmd.OpenReport stDocName, acPreview, , criteria

But when I dim it as a new report the error occurs. Anyway, I tried using
the criteria you suggested and the error occured still:

criteria = "[conso-code]= " & """ & Forms![conso check]!consocode & """ & _
" AND consoid= " & Forms![conso check]!txtConsoId & _
" AND Workshopdate Between " & "#" & Forms![conso
check]!Beginningdate & "#" & _
" And " & "#" & Forms![conso check]!enddate & "#"

Any clues? Thanks again

Richard

--


Ken Snell said:
You must evaluate the parameters outside the string and concatenate the
actual values, not the references. Try this:


criteria = "[conso-code]= " & forms![conso check]!consocode & _
" AND consoid= "forms![conso check]!txtconsoid & _
" AND Workshopdate Between " & Forms![conso
check]!beginningdate & _
" And " & Forms![conso check]!enddate

Note that the above is written assuming that all parameters are providing
numbers (not text or dates). If you are using text or dates, you need to
insert ' on either side of a text string, and # on either side of a date
value (date value must be in mm/dd/yyyy format).

--
Ken Snell
<MS ACCESS MVP>

Richard said:
Hi

I keep getting the error 2498, "An expression you entered is the wrong data
type for one of the arguments"

Can you please check and see which is the worng argument?

Thanks in advance
Richard

Code as follows:
Dim RptInst As New Report_RptConsoRate


If IsNull([consocode]) Then
MsgBox "Please choose report to print", , "Choose client"
Me.consocode.SetFocus
Else
Dim criteria As String

criteria = "[conso-code]= forms![conso check]!consocode " & _
"AND consoid= forms![conso check]!txtconsoid " & _
"AND Workshopdate Between Forms![conso check]!beginningdate
" & _
"And Forms![conso check]!enddate"

DoCmd.OpenReport RptInst, acViewPreview, , criteria
DoCmd.RunCommand acCmdPrint
DoCmd.Close
 
Back
Top