VB for Buttons

M

Mkauley

After realizing that Macro's were a bit limiting, I decided to begin coding
VB for my buttons. So, to that end, I'm trying to get a button to open a
product release sheet for a specific date range (basically everything from
the last two months up through the next 3 months). This is the VB code I use
for the button. It seems to work except that I get an error of "Data type
mismatch in criteria expression"

The Release Date field used is set up as a date field and if I change the
where clause to look at, say, a specific product code in the product code
field, it works fine. Apologies in advance if this isn't the right forum to
post in.

The code is:

Private Sub Command39_Click()
On Error GoTo Err_Command39_Click

Dim st3MonthCond As String

st3MonthCond = "[qryNRSheet]![Release Date]=""Between
DateAdd(m,-2,Date)And DateAdd(m,3,Date)"""

DoCmd.OpenReport "New Release Sheet Report", acViewPreview, , st3MonthCond

Exit_Command39_Click:
Exit Sub

Err_Command39_Click:
MsgBox Err.Description
Resume Exit_Command39_Click

End Sub
 
G

George Nicholson

st3MonthCond = "[qryNRSheet]![Release Date] Between " &
DateAdd("m",-2,Date) & " AND " & DateAdd("m",3,Date)

HTH,
 
M

Mkauley

George,

I changed the code over and it worked better, however now it brings up the
query blank but doesn't give me any errors. There are actual date values set
in the field, so I'm not sure why it isn't working. Any thoughts?

Mkauley


George Nicholson said:
st3MonthCond = "[qryNRSheet]![Release Date] Between " &
DateAdd("m",-2,Date) & " AND " & DateAdd("m",3,Date)

HTH,
--
George Nicholson

Remove 'Junk' from return address.


Mkauley said:
After realizing that Macro's were a bit limiting, I decided to begin
coding
VB for my buttons. So, to that end, I'm trying to get a button to open a
product release sheet for a specific date range (basically everything from
the last two months up through the next 3 months). This is the VB code I
use
for the button. It seems to work except that I get an error of "Data type
mismatch in criteria expression"

The Release Date field used is set up as a date field and if I change the
where clause to look at, say, a specific product code in the product code
field, it works fine. Apologies in advance if this isn't the right forum
to
post in.

The code is:

Private Sub Command39_Click()
On Error GoTo Err_Command39_Click

Dim st3MonthCond As String

st3MonthCond = "[qryNRSheet]![Release Date]=""Between
DateAdd(m,-2,Date)And DateAdd(m,3,Date)"""

DoCmd.OpenReport "New Release Sheet Report", acViewPreview, ,
st3MonthCond

Exit_Command39_Click:
Exit Sub

Err_Command39_Click:
MsgBox Err.Description
Resume Exit_Command39_Click

End Sub
 

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