CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2008
    Posts
    2

    [RESOLVED] Date related problems in VB6 and MS Access

    Hi.
    Here is the code.

    -------------------------------------------------------------------------------------

    Private Sub cmdbrt_Click()

    bkmark2 = ado_books.Recordset.AbsolutePosition

    sqlb = "select * from books where date_of_return < '" & Date & "'"

    ado_books.RecordSource = sqlb
    ado_books.Refresh

    If ado_books.Recordset.RecordCount = 0 Then
    MsgBox "No books late"
    ado_books.RecordSource = "select * from books"
    ado_books.Refresh
    ado_books.Recordset.AbsolutePosition = bkmark2
    End If

    End Sub

    ------------------------------------------------------------------------------------

    The field date_of_return has the value in the format DD-MMM-YY which is similar to what the Date function returns.

    Now the problem is that it shows up an error showing "Data Type Mismatch in Criteria Expression".

    Any idea how to solve this?
    Thanks in advance.

  2. #2
    Join Date
    May 2008
    Posts
    224

    Re: Date related problems in VB6 and MS Access

    MS Access requires you to use the # character on date formats. Like so

    Code:
    sqlb = "select * from books where date_of_return < #" & Date & "#"

  3. #3
    Join Date
    May 2008
    Posts
    2

    Smile Re: Date related problems in VB6 and MS Access

    Hey. Thanks a ton WillAtwell!! You saved my life! It worked perfectly well.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured