By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,594 Members | 2,097 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,594 IT Pros & Developers. It's quick & easy.

Access 2003 and VB 6 Date issues

P: 63
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.Value = 1 And chkEnable2.Value = 0 And chkEnable3.Value = 0 And chkEnable4.Value = 0 And chkEnable5.Value = 0 And chkEnable6.Value = 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.Text = "Operator" Then
MsgBox "You must select an Operator for your search.", vbCritical + vbOKOnly
cboOperator.SetFocus
Exit Sub
ElseIf txtSearch.Text = "Record Search 1" Then
MsgBox "You must enter the record to search for.", vbCritical + vbOKOnly
txtSearch.SetFocus
Exit Sub
Else
XA = Me.txtSearch.Text
MyInfo = cboSearchField.Text & " " & cboOperator.Text & " " & XA
End If
End If
End If

dataSearch.RecordSource = "Select * From 'Ground Activity' Where " & MyInfo

'Go back to last good record found if search returns nothing
varBookmark = dataSearch.Recordset.Bookmark

'Find first instance of MyInfo value. Search starts at the beginning of the database because we use FindFirst
dataSearch.Recordset.FindFirst MyInfo

'Check search results too see if it returns any data
If dataSearch.Recordset.NoMatch = True Then
dataSearch.Recordset.Bookmark = varBookmark
MsgBox "No record not found matching your search criteria.", vbOKOnly
'Me.cmdNewSearch.Enabled = True
cmdFindNext.Enabled = False
cmdFindPrevious.Enabled = False
frmSearchCriteria.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
Nov 27 '06 #1
Share this Question
Share on Google+
4 Replies


Expert 5K+
P: 8,434
...The variable Myinfo is now set to the following
MyInfo = "Date_In = 11/1/2006"
Try building this string...
Expand|Select|Wrap|Line Numbers
  1. MyInfo = "Date_In = #11/1/2006#"
  2.  
Also, if you post code here, please surround it with the [C O D E] and [/C O D E] tags - it's much more easily readable, and much easier to spot odd characters which may cause problems.

P.S. Thanks to NeoPa for the idea about the spaces in "C O D E". :)
Nov 28 '06 #2

P: 63
Thanks a bunch Killer42. Sorry for the error on my posting technique and I will try very hard in the future to post things the way you said. As always, I really appreciate the help and I would never do anything intentionally to offend anyone. I want to learn to be as great a programmer as you and help others as well as you have helped me. Happy and safe holiday season for you and your family!
Nov 28 '06 #3

P: 63
As always, the code worked beautifully that you gave me. Thanks again!
Nov 28 '06 #4

Expert 5K+
P: 8,434
Thanks a bunch Killer42. Sorry for the error on my posting technique and I will try very hard in the future to post things the way you said.
No need to apologise - I was just pointing it out, as it's much more convenient with the tags.
Nov 28 '06 #5

Post your reply

Sign in to post your reply or Sign up for a free account.