T
trezraven
I have created a form using Word 2007 that queries an Access
database. I want my users to be able to search the database by either
entering the type of mandate or a specific date range. My dilema is
my SQL will not let them do one or the other.
For this SQL statement they have to enter both. If they enter an
incorrect mandate type or date range they get the error message.
strSQL = "Select Mandate_Type, Parm1, Agency_Description, CaseNo,
Appellant, Appellee, Lt_Cases, Opinion_Date, Chief_Judge, Mandate_Date
" & _
"From CMS.V_Macro4mandate " & _
"Where Date_Mandate_Released between to_date('" &
DCAMacro.txtStart.Value & "', 'mm/dd/yyyy') and to_date('" &
DCAMacro.txtEnd.Value & "', 'mm/dd/yyyy')" & _
"and Mandate_Type = '" &
DCAMacro.txtMandate_Type.Value & "'" & _
"Order by Appellant "
However, for this SQL statement they can enter one or the other, but
information is returned for a mandate type even if a date range is
entered that is not in the database. For example, if the user enters
a mandate type of MA1 and a date range of 11/1/2007 - 11/30/2007, all
mandate types of MA1 will return even though there is no information
for that particular date range.
strSQL = "Select Mandate_Type, Parm1, Agency_Description, CaseNo,
Appellant, Appellee, Lt_Cases, Opinion_Date, Chief_Judge, Mandate_Date
" & _
"From CMS.V_Macro4mandate " & _
"Where Date_Mandate_Released between to_date('" &
DCAMacro.txtStart.Value & "', 'mm/dd/yyyy') and to_date('" &
DCAMacro.txtEnd.Value & "', 'mm/dd/yyyy')" & _
"or Mandate_Type = '" & DCAMacro.txtMandate_Type.Value
& "'" & _
"Order by Appellant "
'*****Open the recordset*****
rs.Open strSQL, conn, adOenKeyset, adLockOptimistic
'*****Get the data if not end of the record set*****
If rs.EOF Then
MsgBox "No information in the database! Please verify your mandate
type or date range.", vbCritical, "ERROR!"
End If
rs.MoveFirst
If Not rs.EOF Then
Do Until rs.EOF
DCAMacro.txtAppellant = rs.Fields("Appellant").Value & " "
DCAMacro.txtAppellee = rs.Fields("Appellee").Value & " "
DCAMacro.txtCaseNumber = rs.Fields("CaseNo").Value & " "
DCAMacro.txtLowerTrib = rs.Fields("LT_Cases").Value & " "
DCAMacro.txtOpinionDate = rs.Fields("Opinion_Date").Value & " "
DCAMacro.txtStart.Value = " "
'*****Hide the form so the document can come up*****
DCAMacro.Hide
Please help!
database. I want my users to be able to search the database by either
entering the type of mandate or a specific date range. My dilema is
my SQL will not let them do one or the other.
For this SQL statement they have to enter both. If they enter an
incorrect mandate type or date range they get the error message.
strSQL = "Select Mandate_Type, Parm1, Agency_Description, CaseNo,
Appellant, Appellee, Lt_Cases, Opinion_Date, Chief_Judge, Mandate_Date
" & _
"From CMS.V_Macro4mandate " & _
"Where Date_Mandate_Released between to_date('" &
DCAMacro.txtStart.Value & "', 'mm/dd/yyyy') and to_date('" &
DCAMacro.txtEnd.Value & "', 'mm/dd/yyyy')" & _
"and Mandate_Type = '" &
DCAMacro.txtMandate_Type.Value & "'" & _
"Order by Appellant "
However, for this SQL statement they can enter one or the other, but
information is returned for a mandate type even if a date range is
entered that is not in the database. For example, if the user enters
a mandate type of MA1 and a date range of 11/1/2007 - 11/30/2007, all
mandate types of MA1 will return even though there is no information
for that particular date range.
strSQL = "Select Mandate_Type, Parm1, Agency_Description, CaseNo,
Appellant, Appellee, Lt_Cases, Opinion_Date, Chief_Judge, Mandate_Date
" & _
"From CMS.V_Macro4mandate " & _
"Where Date_Mandate_Released between to_date('" &
DCAMacro.txtStart.Value & "', 'mm/dd/yyyy') and to_date('" &
DCAMacro.txtEnd.Value & "', 'mm/dd/yyyy')" & _
"or Mandate_Type = '" & DCAMacro.txtMandate_Type.Value
& "'" & _
"Order by Appellant "
'*****Open the recordset*****
rs.Open strSQL, conn, adOenKeyset, adLockOptimistic
'*****Get the data if not end of the record set*****
If rs.EOF Then
MsgBox "No information in the database! Please verify your mandate
type or date range.", vbCritical, "ERROR!"
End If
rs.MoveFirst
If Not rs.EOF Then
Do Until rs.EOF
DCAMacro.txtAppellant = rs.Fields("Appellant").Value & " "
DCAMacro.txtAppellee = rs.Fields("Appellee").Value & " "
DCAMacro.txtCaseNumber = rs.Fields("CaseNo").Value & " "
DCAMacro.txtLowerTrib = rs.Fields("LT_Cases").Value & " "
DCAMacro.txtOpinionDate = rs.Fields("Opinion_Date").Value & " "
DCAMacro.txtStart.Value = " "
'*****Hide the form so the document can come up*****
DCAMacro.Hide
Please help!