Syntax error

  • Thread starter Thread starter Maracay
  • Start date Start date
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
 
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 & " ' "
 
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
 
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
 

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

Back
Top