MsgBox

idowu100

New member
Local time
Today, 00:48
Joined
Oct 23, 2002
Messages
8
Private Sub cmdrunQry_Click()
Dim db As Database
Dim QD As QueryDef
Dim where As Variant


Set db = CurrentDb

On Error GoTo ErrHandler
db.QueryDefs.Delete ("Dynamic_Query")
'On Error GoTo 0

where = Null
where = where & " AND [County]= '" + Me![County] + "'"
where = where & " AND [RSC Prefix No]= " + Me![RSCPrefixNo]
where = where & " AND [Class]= '" + Me![Class] + "'"
where = where & " AND [Type]= '" + Me![Find] + "'"
where = where & " AND [Town]= '" + Me![Town] + "'"
where = where & " AND [Contaminant]= '" + Me![Contaminant] + "'"
'where = where & " AND [Nuclear]= '" + Me![Clear] + "'"
'where = where & " AND [Voluntary Restrictions?]= '" + Me![VoluntaryRestrictions] + "'"
where = where & " AND [FEPA Order?]= '" + Me![FEPAOrder] + "'"
'where = where & " AND [FSA Order?]= '" + Me![FSAOrder] + "'"

If Not IsNull(Me![DateRestrictionExpires]) Then
where = where & " AND [Date Restriction Expires]= #" & Format(Me![DateRestrictionExpires], "mm dd yyyy") & "#"
'where = where & " AND [Date Restriction Expires]= #" & Me![DateRestrictionExpires] & "#"
End If

If Not IsNull(Me![Nuclear]) Then
If Me![Nuclear] = "Yes" Then where = where & " AND [Nuclear]= -1"
If Me![Nuclear] = "No" Then where = where & " AND [Nuclear]= 0"
End If

If Not IsNull(Me![Voluntary Restrictions?]) Then
If Me![VoluntaryRestrictions] = "Yes" Then where = where & " AND [Voluntary Restrictions?]= -1"
If Me![VoluntaryRestrictions] = "No" Then where = where & " AND [Voluntary Restrictions?]= 0"
End If

If Not IsNull(Me![FSA Order?]) Then
If Me![FSAOrder] = "Yes" Then where = where & " AND [FSA Order?]= -1"
If Me![FSAOrder] = "No" Then where = where & " AND [FSA Order?]= 0"
End If

If Not IsNull(Me![DateRestrictionImposed]) Then
where = where & " AND [Date Restriction Imposed]= #" & Format(Me![DateRestrictionImposed], "mm dd yyyy") & "#"

End If


'If Not IsNull(Me![IncidentStartDate]) Then
'where = where & " AND [Incident Date]>= #" & Format(Me![IncidentStartDate], "dd mm yyyy") & "#"
'where = where & " AND [Incident Date]> = #" & Format(Me![IncidentEndDate], "dd mm yyyy") & "#"

'where = where & " AND [Incident Date] = #" + Me![IncidentStartDate] _
'+ " #"


If Not IsNull(Me![IncidentStartDate]) Then
If Not IsNull(Me![IncidentStartDate]) Then
where = where & " AND [Incident Date] between #" + _
Format(Me![IncidentStartDate], "mm dd yyyy") + "# AND #" & Format(Me![IncidentEndDate], "mm dd yyyy") & "#"
Else
where = where & " AND [Incident Date] >= #" + Format(Me![IncidentStartDate], "mm dd yyyy") _
+ " #"

End If
End If

MsgBox "Select * from Incidents " & (" where " + Mid(where, 6) & ";")
Set QD = db.CreateQueryDef("Dynamic_Query", _
"Select* from Incidents " & (" where " + Mid(where, 6) & ";"))
DoCmd.OpenReport "Report1", acViewPreview, "qryDynamic_QBF"

'Displays Query(Dynamic_Query) Results Through Query Data View.
'Displays Query(Dynamic_Query) Results In A Report(REPORT1) View.
'DoCmd.OpenQuery "Dynamic_Query"
'DoCmd.OpenReport "Report1", acViewPreview, "qryDynamic_QBF"



ExitCode:
Exit Sub

ErrHandler:

Select Case Err.Number

Case 2501
Resume ExitCode

Case Else
Resume Next 'but this is not ideal. It is better to trap errors rather than ignoring them!

End Select








End Sub
Private Sub CmdRefresh_Click()
On Error GoTo Err_CmdRefresh_Click


DoCmd.DoMenuItem acFormBar, acRecordsMenu, 5, , acMenuVer70

Exit_CmdRefresh_Click:
Exit Sub

Err_CmdRefresh_Click:
MsgBox Err.Description
Resume Exit_CmdRefresh_Click

End Sub
Private Sub CmdExit_Click()
On Error GoTo Err_CmdExit_Click


DoCmd.Close
Forms![frmMainMenu].Visible = True

Exit_CmdExit_Click:
Exit Sub

Err_CmdExit_Click:
MsgBox Err.Description
Resume Exit_CmdExit_Click

End Sub

Private Sub Combo81_BeforeUpdate(Cancel As Integer)

End Sub
Private Sub CmdDelete_Click()
On Error GoTo Err_CmdDelete_Click


DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

Exit_CmdDelete_Click:
Exit Sub

Err_CmdDelete_Click:
MsgBox Err.Description
Resume Exit_CmdDelete_Click

End Sub

Private Sub Command31_Click()








End Sub

Private Sub Command85_Click()
County = Null
RSCPrefixNo = Null
Class = Null
Find = Null
Town = Null
Contaminant = Null
Nuclear = Null
VoluntaryRestrictions = Null
FEPAOrder = Null
FSAOrder = Null
DateRestrictionImposed = Null
DateRestrictionExpires = Null
IncidentStartDate = Null
IncidentEndDate = Null

This is my code on my search criteria. I need to know how to tell the user if there are no records matching their search.

Many thanks.
 

Users who are viewing this thread

Back
Top Bottom