Syntax error

M

Maracay

Hi guys

The next set of instructions are in a click event of a command button, the
first section is ok, but the second one (stWhere = stWhere & " And txtMa....)
I am getting an syntax error, I'm sure I' m missing something, I will
appreciate any help,

Thanks

Dim stWhere As String
stWhere = "dReportDate Between " & Format(txtFrom, "\#yyyy-m-d\#") & " And
" & Format(txtTo, "\#yyyy-m-d\#")
stWhere = stWhere & " And txtMachineID = #" & Me.ComboMachine & "# "

DoCmd.OpenReport "rptDetMachineOp1&notOp1", acViewPreview, _
WhereCondition:=stWhere
 
D

Douglas J. Steele

Sounds as though txtMachineID isn't a date, so there's no need for the #
characters there.

If it's a number, use

stWhere = stWhere & " And txtMachineID = " & Me.ComboMachine

If it's a string, use

stWhere = stWhere & " And txtMachineID = '" & Me.ComboMachine & "'"

Exagerated for clarity, that's

stWhere = stWhere & " And txtMachineID = ' " & Me.ComboMachine & " ' "
 
M

Maracay

Thanks, is working fine, but now I would like in the case no machine is
include in the combo box, the report should retrieve all the machines that
can find, the same is for the date from and date to, if no date is include,
it should bring all the dates that can find.

Thanks
 
D

Douglas J. Steele

Dim stWhere As String

stWhere = "dReportDate Between " & _
Format(txtFrom, "\#yyyy-m-d\#") & " And" & _
Format(txtTo, "\#yyyy-m-d\#")

If IsNull(Me.ComboMachine) = False Then
stWhere = stWhere & " And txtMachineID = " & _
Me.ComboMachine
End If
 
Top