i have a form that is used to enter 4 values in a tblmonthlyunits. they are:
salesperson (text), monthandyear (date in the format mmm-yyyy), department
(text) and units (gen. number). i have a search button on this form that
opens a 2nd form, formsearchmontlyunits, where a user would enter 1 or more
values to do a search with, then those values are formed into an sql that is
used to filter the first form. my problem is that i didn't write this code (i
do understand it, but i seemingly can't debug it). now that i've change a
few things in the forms, the code doesn't work.
it gets hung up at the dlookup function where it is supposed to verify that
there are records present that meet the criteria. my thought is the problem
is the date format. i did a msgbox for the where on the sql and got (date) =
10/01/2005 even though my entry on the search form was oct-2005 (this is how
the records are stored in the table). here's the code:
Private Sub cmdEdit_Click()
Dim strWhere As String
Dim strF As String
strWhere = BuildWhere
' the form is already open...so we set the filter..not the "where"
' however, BEFORE we do this, lets make sure some reocrds match!!
If DCount("*", "tblsoldunits", strWhere) = 0 Then
MsgBox "no records found", vbExclamation, "no match"
Else
' got some rocords...lets filter
strF = "formmonthlyunits"
Forms(strF).Filter = strWhere
Forms(strF).FilterOn = True
DoCmd.Close acForm, Me.Name
End If
End Sub
Function CheckFields()
' check for required fields
' returns false if required fields missing
If IsNull(Me.tboxmonthandyear) = True Then
MsgBox "Month and Year are required", vbExclamation, "Date required"
Me.tboxmonthandyear.SetFocus
Exit Function
End If
End Function
Function BuildWhere() As String
Dim strTemp As String
Dim strWhere As String
Dim strField As String
Dim strControl As String
If (IsNull(Me.tboxmonthandyear) = False) Then
strWhere = "([Date] = " & "#" & (Me.tboxmonthandyear) & "#)"
End If
Call AddWhere("cboxSalesperson", "Salesperson", strWhere)
Call AddWhere("cboxdepartment", "Department", strWhere)
BuildWhere = strWhere
End Function
Sub AddWhere(strControl As String, strField As String, strWhere As String)
If IsNull(Me(strControl)) = False Then
If strWhere <> "" Then
strWhere = strWhere & " and "
End If
strWhere = strWhere & "(" & strField & " = " & """ & "(Me(strControl).
Value) & ")" & """
End If
End Sub
thanks for looking.
--
Message posted via http://www.accessmonster.com