Dim cnt As Integer
Dim ctl As Control
Dim nill As String
Dim ssql As String
Dim Hold As String
Dim db As Database
Dim rs As Recordset
Dim isblank As Boolean
Set db = CurrentDb()
isblank = True
cnt = 0
'figure out which search boxes are filled in
' If Nz(Me.fldPermitNo, "") & "" <> "" Then cnt = cnt + 1 'one method but didn't use
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
Debug.Print ctl.Name
If ctl <> "" Then
cnt = cnt + 1
End If
End If
Next ctl
If cnt = 0 Then
MsgBox "You must enter something to search for.."
fldPermitNo.SetFocus
Exit Sub
End If
ssql = "Select distinct " & _
"a.fldPermitNo, " & _
"a.fldLastName, " & _
"a.fldFirstName, " & _
"a.fldMiddleInit, " & _
"a.fldLocation, " & _
"a.fldTeamGroupUnit, " & _
"a.fldGroupUnit, " & _
"a.fldWorkPhone, " & _
"a.fldOrganizationNo, " & _
"a.fldId, " & _
"a.fldInsCo, " & _
"a.fldPolicyNo, " & _
"a.fldMemo, " & _
"a.fldLastUpdated, " & _
"b.fldVehMake, " & _
"b.fldVehModel, " & _
"b.fldLicenseNo, " & _
"b.fldDescription, " & _
"b.fldVehState, " & _
"b.fldVehYear " & _
"FROM tblParkingPermitAppl a, tblParkingPermitVehList b " & _
"Where b.fldPermitNo = a.fldPermitNo "
For Each ctl In Me.Controls
If ctl.ControlType = acTextBox Then
Debug.Print ctl.Name
If ctl <> "" Then
Select Case ctl.Name
Case "fldPermitNo" 'permit number
If DCount("*", "tblParkingPermitAppl", "fldPermitNo='" & fldPermitNo & "'") = 0 Then
MsgBox "zero records.", vbInformation, "System Error"
Else
ssql = ssql + " AND a.fldPermitNo = '" & fldPermitNo & "'"
' Debug.Print ssql
End If
Case "fldLastName" 'last name
If DCount("*", "tblParkingPermitAppl", "fldLastName='" & fldLastName & "'") = 0 Then
MsgBox "zero records.", vbInformation, "System Error"
Else
ssql = ssql + " AND a.fldLastName = '" & fldLastName & "'"
' Debug.Print ssql
End If
Case "fldFirstName" 'first name
If DCount("*", "tblParkingPermitAppl", "fldFirstName='" & fldFirstName & "'") = 0 Then
MsgBox "zero records.", vbInformation, "System Error"
Else
ssql = ssql + " AND a.fldFirstName = '" & fldFirstName & "'"
' Debug.Print ssql
End If
Case "fldMiddleInit" 'middle initial
If DCount("fldMiddleInit", "tblParkingPermitAppl", "fldMiddleInit='" & fldMiddleInit & "'") = 0 Then
MsgBox "zero records.", vbInformation, "System Error"
Else
ssql = ssql + " AND a.fldMiddleInit = '" & fldMiddleInit & "'"
' Debug.Print ssql
End If
Case "fldid" 'wssc emp id
If DCount("*", "tblParkingPermitAppl", "fldid='" & fldId & "'") = 0 Then
MsgBox "zero records.", vbInformation, "System Error"
Else
ssql = ssql + " AND a.fldid = '" & fldId & "'"
'Debug.Print ssql
End If
Case "fldLicenseNo" 'license number
If DCount("*", "tblParkingPermitAppl", "fldLicenseNo='" & fldLicenseNo & "'") = 0 Then
MsgBox "zero records.", vbInformation, "System Error"
Else
ssql = ssql + " AND b.fldLicenseNo = '" & fldLicenseNo & "'"
' Debug.Print ssql
End If
Case "fldVehYear" 'Vehicle Year
If DCount("*", "tblParkingPermitAppl", "fldVehYear='" & fldVehYear & "'") = 0 Then
MsgBox "zero records.", vbInformation, "System Error"
Else
ssql = ssql + " AND b.fldVehYear = " & fldVehYear & ""
'Debug.Print ssql
End If
Case "fldVehMake" 'Vehicle Make
If DCount("*", "tblParkingPermitAppl", "fldVehMake='" & fldVehMake & "'") = 0 Then
MsgBox "zero records.", vbInformation, "System Error"
Else
ssql = ssql + " AND b.fldVehMake = '" & fldVehMake & "'"
' Debug.Print ssql
End If
Case "fldVehModel" 'Vehicle Model
If DCount("*", "tblParkingPermitAppl", "fldVehModel='" & fldVehModel & "'") = 0 Then
MsgBox "zero records.", vbInformation, "System Error"
Else
ssql = ssql + " AND b.fldVehModel = '" & fldVehModel & "'"
' Debug.Print ssql
End If
Case Else
'do nothing
End Select
' Debug.Print ctl.Name
Else
'skip it
End If
End If
Next ctl
Debug.Print ssql
' Open the Parking Permit Application Form and populate the fields.
Forms("frmParkingPermitAppl").RecordSource = ssql
DoCmd.OpenForm "frmParkingPermitAppl", acNormal
[Forms]![frmParkingPermitAppl]!ViewAllRecords.Enabled = True
[Forms]![frmParkingPermitAppl].AllowDeletions = True
'Set field values on the Search screen to null once a valid record is found and close _
the Screen.
fldPermitNo = Null
fldLastName = Null
fldFirstName = Null
fldMiddleInit = Null
fldId = Null
fldVehYear = Null
fldVehMake = Null
fldVehModel = Null
fldLicenseNo = Null
fldPermitNo.SetFocus
[Forms]![frmSearch].[Visible] = False