List Box

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jonny

    #1

    List Box

    Hello,

    Firstly, I fill in a form for each record, which contains things like
    name, date from, date to etc.

    I have a list form in my database, which when opened displays certain
    information from my records (name, date from, date to etc).

    I also have a few text boxes on the list form, which when text is
    entered into them, the list box on the form is filtered accordingly
    (so if I type my name, only the records I have entered are shown in
    the list box.

    However, I have a problem with the date boxes, as I want to use a
    between statement, so if the record has dates between a range, then it
    should show in the list, all others should be excluded.

    The code I am using is below (however, I have used this code for
    another DB, and just ripped it from there):

    Private Sub TxtDateTo_After Update()
    Dim strsql As String
    strsql = "SELECT ID,Name,Event,M ember,DateFrom, DateTo FROM
    TblMain WHERE 1 = 1"
    If Len(TxtDateFrom ) > 0 Then
    strsql = strsql & " AND DateFrom like '*" & TxtDateFrom & "*'"
    End If
    If Len(TxtName) > 0 Then
    strsql = strsql & " AND Technician like '*" & TxtTechnician &
    "*'"
    End If
    If Len(TxtMember) > 0 Then
    strsql = strsql & " AND ProductSupport like '*" &
    TxtProductSuppo rt & "*'"
    End If
    If Len(TxtDateTo) > 0 Then
    strsql = strsql & " AND DateTo like '*" & TxtDateTo & "*'"
    End If
    strsql = strsql & " Order by Name;"
    Lstcustomers.Ro wSource = strsql
    Call Countrecords
    If Lstcustomers.Li stCount = 0 Then
    MsgBox "No Records Were Found, Please Click on Clear and Redefine
    Your Search", vbOKOnly, "No Records Found"
    End If
    End Sub

    I have the code above for each of the fields on the list form, but
    obviously each one is slightly different.

    However, I can't seem to get it to work for the dates, and am not sure
    of the syntax I need in order to get the between statement to work.

    Can anyone please help ?

    If none of the above makes sense, please let me know, either on here,
    or by mailing jonnymenthol@ya hoo.com

    Thanks in advance

    Jonny.
  • Tom van Stiphout

    #2
    Re: List Box

    On 8 Jun 2004 02:14:05 -0700, jonnymenthol@ya hoo.com (Jonny) wrote:

    Date values must be wrapped in #-signs.
    -Tom.


    [color=blue]
    >Hello,
    >
    >Firstly, I fill in a form for each record, which contains things like
    >name, date from, date to etc.
    >
    >I have a list form in my database, which when opened displays certain
    >information from my records (name, date from, date to etc).
    >
    >I also have a few text boxes on the list form, which when text is
    >entered into them, the list box on the form is filtered accordingly
    >(so if I type my name, only the records I have entered are shown in
    >the list box.
    >
    >However, I have a problem with the date boxes, as I want to use a
    >between statement, so if the record has dates between a range, then it
    >should show in the list, all others should be excluded.
    >
    >The code I am using is below (however, I have used this code for
    >another DB, and just ripped it from there):
    >
    >Private Sub TxtDateTo_After Update()
    > Dim strsql As String
    > strsql = "SELECT ID,Name,Event,M ember,DateFrom, DateTo FROM
    >TblMain WHERE 1 = 1"
    > If Len(TxtDateFrom ) > 0 Then
    > strsql = strsql & " AND DateFrom like '*" & TxtDateFrom & "*'"
    > End If
    > If Len(TxtName) > 0 Then
    > strsql = strsql & " AND Technician like '*" & TxtTechnician &
    >"*'"
    > End If
    > If Len(TxtMember) > 0 Then
    > strsql = strsql & " AND ProductSupport like '*" &
    >TxtProductSupp ort & "*'"
    > End If
    > If Len(TxtDateTo) > 0 Then
    > strsql = strsql & " AND DateTo like '*" & TxtDateTo & "*'"
    > End If
    > strsql = strsql & " Order by Name;"
    > Lstcustomers.Ro wSource = strsql
    > Call Countrecords
    > If Lstcustomers.Li stCount = 0 Then
    > MsgBox "No Records Were Found, Please Click on Clear and Redefine
    >Your Search", vbOKOnly, "No Records Found"
    > End If
    >End Sub
    >
    >I have the code above for each of the fields on the list form, but
    >obviously each one is slightly different.
    >
    >However, I can't seem to get it to work for the dates, and am not sure
    >of the syntax I need in order to get the between statement to work.
    >
    >Can anyone please help ?
    >
    >If none of the above makes sense, please let me know, either on here,
    >or by mailing jonnymenthol@ya hoo.com
    >
    >Thanks in advance
    >
    >Jonny.[/color]

    Comment

    Working...