Advertisement
Advertisement
| 06.04.2008 at 12:45PM PDT, ID: 23458105 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: |
Function BuildSQLString(strSQL As String) As Boolean
Dim strWHERE As String
Dim ctl As Control
Dim i As Integer
For Each ctl In Me.Form.Controls
If ctl.ControlType = acTextBox Then
For i = 1 To Me.Form.Controls.Count
If Not IsNull(ctl) Then
If IsNumeric(ctl) Then 'This is a number
strWHERE = strWHERE & " And " & ctl.Name & " = " & ctl
ElseIf IsDate(ctl) Then 'This is a date
strWHERE = strWHERE & " And " & ctl.Name & " =#" & ctl & "#"
Else 'This is text
strWHERE = strWHERE & " And " & ctl.Name & "='" & ctl & "'"
End If
End If
Next i
strWHERE = strWHERE
End If
Next ctl
strSQL = "SELECT * FROM [Lot Specs]"
If strWHERE <> "" Then strSQL = strSQL & " WHERE " & Mid$(strWHERE, 6)
BuildSQLString = True
End Function
Private Sub cmdFind_Click()
On Error GoTo Err_Handler
Dim strSQL As String
Dim stDocName As String
Dim strMsg As String
Dim strCount As String
stDocName = "qrySearchForm"
If Not BuildSQLString(strSQL) Then
MsgBox "There was a problem building the string"
Exit Sub
End If
CurrentDb.QueryDefs(stDocName).SQL = strSQL
RefreshDatabaseWindow
strCount = DCount("*", stDocName)
strMsg = "There are " & strCount & " Records Found" & vbCrLf & vbCrLf & _
"Do You Want To View These Records?"
If MsgBox(strMsg, vbYesNo) = vbYes Then
DoCmd.OpenQuery stDocName, , acReadOnly
End If
Exit_Handler:
Exit Sub
Err_Handler:
MsgBox Err.Number & " " & Err.Description
Resume Exit_Handler
End Sub
|