Access 2003 and VB 6 Date issues

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • keithsimpson3973
    New Member
    • Aug 2006
    • 63

    Access 2003 and VB 6 Date issues

    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
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Originally posted by keithsimpson397 3
    ...The variable Myinfo is now set to the following
    MyInfo = "Date_In = 11/1/2006"
    Try building this string...
    Code:
    MyInfo = "Date_In = [B]#[/B]11/1/2006[B]#[/B]"
    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". :)

    Comment

    • keithsimpson3973
      New Member
      • Aug 2006
      • 63

      #3
      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!

      Comment

      • keithsimpson3973
        New Member
        • Aug 2006
        • 63

        #4
        As always, the code worked beautifully that you gave me. Thanks again!

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Originally posted by keithsimpson397 3
          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.

          Comment

          Working...