Please forgive me for being so stupid. I have searched this site and many others for what should be a simple thing. I have a vb 6 form with a textbox that I input a date into. I can't set the format for the textbox on the vb6 form because it is a bound form using a data control. Here is the code I am using.
The field in the Access Database "Date_In" is a date/time field
I select "Date_In" from the first combo box, then I select "=" fron the second combo box, then I enter the date "11/1/2006".
When I run the search it finds no records even though there is a record in the database that matches the search criteria
The variable Myinfo is now set to the following
MyInfo = "Date_In = 11/1/2006"
Dim XA As Date
If cboSearchField. Text = "Date_In" Or cboSearchField2 .Text = "Date_In" _
Or cboSearchField3 .Text = "Date_In" Or cboSearchField4 .Text = "Date_In" Or _
cboSearchField5 .Text = "Date_In" Or cboSearchField6 .Text = "Date_In" Then
If chkEnable1.Valu e = 1 And chkEnable2.Valu e = 0 And chkEnable3.Valu e = 0 And chkEnable4.Valu e = 0 And chkEnable5.Valu e = 0 And chkEnable6.Valu e = 0 Then
If cboSearchField. Text = "Search Field" Then
MsgBox "You must select a database field to search in.", vbCritical + vbOKOnly
cboSearchField. SetFocus
Exit Sub
ElseIf cboOperator.Tex t = "Operator" Then
MsgBox "You must select an Operator for your search.", vbCritical + vbOKOnly
cboOperator.Set Focus
Exit Sub
ElseIf txtSearch.Text = "Record Search 1" Then
MsgBox "You must enter the record to search for.", vbCritical + vbOKOnly
txtSearch.SetFo cus
Exit Sub
Else
XA = Me.txtSearch.Te xt
MyInfo = cboSearchField. Text & " " & cboOperator.Tex t & " " & XA
End If
End If
End If
dataSearch.Reco rdSource = "Select * From 'Ground Activity' Where " & MyInfo
'Go back to last good record found if search returns nothing
varBookmark = dataSearch.Reco rdset.Bookmark
'Find first instance of MyInfo value. Search starts at the beginning of the database because we use FindFirst
dataSearch.Reco rdset.FindFirst MyInfo
'Check search results too see if it returns any data
If dataSearch.Reco rdset.NoMatch = True Then
dataSearch.Reco rdset.Bookmark = varBookmark
MsgBox "No record not found matching your search criteria.", vbOKOnly
'Me.cmdNewSearc h.Enabled = True
cmdFindNext.Ena bled = False
cmdFindPrevious .Enabled = False
frmSearchCriter ia.Show
cboSearchField. SetFocus
Exit Sub
End If
Please accept my humble apologies if this has been answered elsewhere in this forum as I can't find it if there is.
Thanks a bunch
The field in the Access Database "Date_In" is a date/time field
I select "Date_In" from the first combo box, then I select "=" fron the second combo box, then I enter the date "11/1/2006".
When I run the search it finds no records even though there is a record in the database that matches the search criteria
The variable Myinfo is now set to the following
MyInfo = "Date_In = 11/1/2006"
Dim XA As Date
If cboSearchField. Text = "Date_In" Or cboSearchField2 .Text = "Date_In" _
Or cboSearchField3 .Text = "Date_In" Or cboSearchField4 .Text = "Date_In" Or _
cboSearchField5 .Text = "Date_In" Or cboSearchField6 .Text = "Date_In" Then
If chkEnable1.Valu e = 1 And chkEnable2.Valu e = 0 And chkEnable3.Valu e = 0 And chkEnable4.Valu e = 0 And chkEnable5.Valu e = 0 And chkEnable6.Valu e = 0 Then
If cboSearchField. Text = "Search Field" Then
MsgBox "You must select a database field to search in.", vbCritical + vbOKOnly
cboSearchField. SetFocus
Exit Sub
ElseIf cboOperator.Tex t = "Operator" Then
MsgBox "You must select an Operator for your search.", vbCritical + vbOKOnly
cboOperator.Set Focus
Exit Sub
ElseIf txtSearch.Text = "Record Search 1" Then
MsgBox "You must enter the record to search for.", vbCritical + vbOKOnly
txtSearch.SetFo cus
Exit Sub
Else
XA = Me.txtSearch.Te xt
MyInfo = cboSearchField. Text & " " & cboOperator.Tex t & " " & XA
End If
End If
End If
dataSearch.Reco rdSource = "Select * From 'Ground Activity' Where " & MyInfo
'Go back to last good record found if search returns nothing
varBookmark = dataSearch.Reco rdset.Bookmark
'Find first instance of MyInfo value. Search starts at the beginning of the database because we use FindFirst
dataSearch.Reco rdset.FindFirst MyInfo
'Check search results too see if it returns any data
If dataSearch.Reco rdset.NoMatch = True Then
dataSearch.Reco rdset.Bookmark = varBookmark
MsgBox "No record not found matching your search criteria.", vbOKOnly
'Me.cmdNewSearc h.Enabled = True
cmdFindNext.Ena bled = False
cmdFindPrevious .Enabled = False
frmSearchCriter ia.Show
cboSearchField. SetFocus
Exit Sub
End If
Please accept my humble apologies if this has been answered elsewhere in this forum as I can't find it if there is.
Thanks a bunch
Comment