Whats wrong with this code

A

AMDGUY [MCP]

Private Sub Command6_Click()
Dim db As DAO.Database
Dim qd As QueryDef
Dim where As Variant
Set db = CurrentDb()
On Error Resume Next
db.QueryDefs.Delete ("DATEQuery")
On Error GoTo 0
where = Null
If Not IsNull(Me![fromdate]) Then
If Not IsDate(Me![fromdate]) Then
MsgBox "The value in from is not a valid date.", _
vbCritical, gstrapptitle
Exit Sub
End If
If Not IsNull(Me![todate]) Then
If Not IsDate(Me![todate]) Then
MsgBox "The value in to is not a valid date.", _
vbCritical, gstrapptitle
Exit Sub
End If
End If
End If
Set qd = db.CreateQueryDef("DATEQuery", _
"select * from DATE " & (" where " + Mid(where, 6) & ";"))
End Sub
 
G

Guest

hi,
where is a reserved word. cant use as dim
Date is a reserved word. cant use as table name.
 
A

AMDGUY [MCP]

FIXED IT HERES WHAT I USED BUT I CANT FIGURE OUT WHY IT ONLY OPENS 2 OF
THE REPORTS TWICE.
IT OPENS "MACH" AND "PART CAT" TWICE AND WONT OPEN THE "EMPLOYEE" AND
"PART IR"
Private Sub Show_Reports_Click()
Dim db As DAO.Database
Dim qd As QueryDef
Dim where As Variant
Set db = CurrentDb()
On Error Resume Next
db.QueryDefs.Delete ("DATAQuery")
On Error GoTo 0
where = Null
If Not IsNull(Me![fromdate]) Then
If Not IsDate(Me![fromdate]) Then
MsgBox "The value in from is not a valid date.", _
vbCritical, gstrapptitle
Exit Sub
End If
If Not IsNull(Me![todate]) Then
If Not IsDate(Me![todate]) Then
MsgBox "The value in to is not a valid date.", _
vbCritical, gstrapptitle
Exit Sub
End If
End If
End If
If Not IsNull(Me![todate]) Then
where = where & " and [DATE] between #" + _
Me![fromdate] + "# and #" & Me![todate] & "#"
Else
where = where & " and [DATE] >= #" + Me![fromdate] + " #"
End If
Set qd = db.CreateQueryDef("DATAQuery", _
"select * from DATA " & (" where " + Mid(where, 6) & ";"))
DoCmd.OpenReport "Employee", acViewPreview
DoCmd.OpenReport "MACH", acViewPreview
DoCmd.OpenReport "PART CAT", acViewPreview
DoCmd.OpenReport "PART IR", acViewPreview
End Sub


hi,
where is a reserved word. cant use as dim
Date is a reserved word. cant use as table name.

-----Original Message-----
Private Sub Command6_Click()
Dim db As DAO.Database
Dim qd As QueryDef
Dim where As Variant
Set db = CurrentDb()
On Error Resume Next
db.QueryDefs.Delete ("DATEQuery")
On Error GoTo 0
where = Null
If Not IsNull(Me![fromdate]) Then
If Not IsDate(Me![fromdate]) Then
MsgBox "The value in from is not a valid date.",
_

vbCritical, gstrapptitle
Exit Sub
End If
If Not IsNull(Me![todate]) Then
If Not IsDate(Me![todate]) Then
MsgBox "The value in to is not a valid

date.", _
vbCritical, gstrapptitle
Exit Sub
End If
End If
End If
Set qd = db.CreateQueryDef("DATEQuery", _
"select * from DATE " & (" where " + Mid(where, 6) & ";"))
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