Results 1 to 22 of 22

Thread: simple ? for anyone besides me

  1. #1

    Thread Starter
    Hyperactive Member PJB's Avatar
    Join Date
    Aug 2000
    Location
    dunno at the moment
    Posts
    302
    I've got 2 masked edit boxes (mask = ##/##/####) i want the user to be able to input the dates and have it select all dates between and including the user inputted from my database

    I can get it to work if i put the dates directly into the SELECT statement but not having any luck otherwise
    VB6.0 SP4
    Windows 2000
    I'm thinking of a number between

  2. #2
    Hyperactive Member barrk's Avatar
    Join Date
    Sep 2000
    Location
    My own little world
    Posts
    274
    If I understand what you are trying to do this may help. Get your input from the text boxes as variables, convert them, and insert them into your sql statement

    dim date1 as string
    dim date2 as string

    date1 = text1.text 'your starting date
    date2 = text2.text 'your ending date

    sqlstring = "select * from mytable where date between " & format(date, date1) " and " & format(date, date2)

    Hope this helps.

  3. #3

    Thread Starter
    Hyperactive Member PJB's Avatar
    Join Date
    Aug 2000
    Location
    dunno at the moment
    Posts
    302
    I've been trying something similiar to that and end up getting no records returned, but with your code i'm at least not getting an error so it's a start...
    VB6.0 SP4
    Windows 2000
    I'm thinking of a number between

  4. #4
    Hyperactive Member barrk's Avatar
    Join Date
    Sep 2000
    Location
    My own little world
    Posts
    274
    PJB Can you show me what your code looks like. I'd like to help if I can!

  5. #5

    Thread Starter
    Hyperactive Member PJB's Avatar
    Join Date
    Aug 2000
    Location
    dunno at the moment
    Posts
    302
    this code is what i'm using to dynamically set up different reports, as i say if i put the actual dates in my SQL statement it works fine, the mask on the masked edit boxes is ##/##/#### and in my database the PayDate field is set to short date

    Code:
    Private Sub cmdPrint_Click()
    Dim DateFrom As String
    Dim DateTo As String
    
    DateFrom = mskFrom.Text
    DateTo = mskTo.Text
    sqlstring = "Select * from GEService Where PayDate Between " & Format(Date, DateFrom) & " and " & Format(Date, DateTo) & ""
        With cmd
            .ActiveConnection = cn
            .CommandType = adCmdText
            .CommandText = sqlstring
            .Execute
        End With
        
        With rs
            .ActiveConnection = cn
            .CursorLocation = adUseClient
            .Open cmd
        End With
       
       Dim q As Integer
       Dim intCtrl As Integer
       Dim x As Integer
       Dim z As Integer
       x = 0
       q = 0
       z = 0
    
       With DataReport6
       
       Set .DataSource = rs
       .DataMember = ""
       With .Sections("Section1").Controls
           For intCtrl = 1 To .Count
         If TypeOf .Item(intCtrl) Is RptLabel Then
                    .Item(intCtrl).Caption = rs.Fields(q).Name & " :"
                     q = q + 1
                End If
                If TypeOf .Item(intCtrl) Is RptTextBox Then
                    .Item(intCtrl).DataMember = ""
                    .Item(intCtrl).DataField = rs(z).Name
                    z = z + 1
                End If
        Next intCtrl
       End With
       .Refresh
       .Show
       End With
       Unload Me
    End Sub
    thanks for the help you've already given
    VB6.0 SP4
    Windows 2000
    I'm thinking of a number between

  6. #6
    Hyperactive Member barrk's Avatar
    Join Date
    Sep 2000
    Location
    My own little world
    Posts
    274
    Private Sub cmdPrint_Click()
    Dim DateFrom As string
    Dim DateTo As String

    DateFrom = mskFrom.Text
    DateTo = mskTo.Text
    sqlstring = "Select * from GEService Where PayDate


    *********
    try adding tick marks before and after your dates

    Between '" & Format(Date, DateFrom) & "' and '" &
    Format(Date, DateTo) & "'"
    *********






    With cmd
    .ActiveConnection = cn
    .CommandType = adCmdText
    .CommandText = sqlstring
    .Execute
    End With

  7. #7
    Hyperactive Member barrk's Avatar
    Join Date
    Sep 2000
    Location
    My own little world
    Posts
    274
    One more thing.....

    I was wrong to tell you to change the format to date. Since you are passing the value to a string you don't need to. Your code should look like this:

    Private Sub cmdPrint_Click()
    Dim DateFrom As String
    Dim DateTo As String

    DateFrom = mskFrom.Text
    DateTo = mskTo.Text
    sqlstring = "Select * from GEService Where PayDate Between '" & DateFrom & "' and '" & DateTo & "'"

    try debug.print on sqlstring to see if you are getting a valid sql statement. I tried it and it works for me.

  8. #8

    Thread Starter
    Hyperactive Member PJB's Avatar
    Join Date
    Aug 2000
    Location
    dunno at the moment
    Posts
    302
    that gives me an error that says "data type mismatch in criteria expression"
    VB6.0 SP4
    Windows 2000
    I'm thinking of a number between

  9. #9
    Hyperactive Member barrk's Avatar
    Join Date
    Sep 2000
    Location
    My own little world
    Posts
    274
    Did you add the tick marks before and after the dates??

    sqlstring = "Select * from GEService Where PayDate Between '" & DateFrom & "' and '" & DateTo & "'"

    Just out of curiousity, what database are you extracting the data from?




  10. #10

    Thread Starter
    Hyperactive Member PJB's Avatar
    Join Date
    Aug 2000
    Location
    dunno at the moment
    Posts
    302
    yup i put the tick marks in, it's a Access 97 database the data type for this field is set to Date/Time and the format is set to shortdate
    VB6.0 SP4
    Windows 2000
    I'm thinking of a number between

  11. #11
    Hyperactive Member barrk's Avatar
    Join Date
    Sep 2000
    Location
    My own little world
    Posts
    274
    Hello PJB

    If you haven't lost faith in me or found the answer yourself I think I've figured out what my problem was.

    I had the format statement hosed up.

    try this:

    Dim DateFrom As String
    Dim DateTo As String

    DateFrom = mskFrom.Text
    DateTo = mskTo.Text
    sqlstring = "Select * from GEService Where PayDate Between '" & Format(DateFrom, "mm/dd/yy") & "' and '" & Format(DateTo, "mm/dd/yy") & "'"

    You do still need the tick marks if you run this statement in SQL Server. Also you can substitute another date format if you require (i.e. "dd-mmm-yy")

  12. #12

    Thread Starter
    Hyperactive Member PJB's Avatar
    Join Date
    Aug 2000
    Location
    dunno at the moment
    Posts
    302
    with th tick marks it gives me the same dat type mismatch and without it gives me a blank form
    I tried this
    Code:
    Select * From GEService Where Paydate Between #01/01/2000# And #12/25/2002#
    and it works alright
    i just tried changing my statement to
    Code:
    Dim DateFrom As String
    Dim DateTo As String
    
    DateFrom = mskFrom.Text
    DateTo = mskTo.Text
    sqlstring = "Select * from GEService Where PayDate Between '" & FormatDateTime(DateFrom, "mm/dd/yyyy") & "' and '" & FormatDateTime(DateTo, "mm/dd/yyyy") & "'"
    and i just get an error that says Type Mismatch

    [Edited by PJB on 10-04-2000 at 06:39 PM]
    VB6.0 SP4
    Windows 2000
    I'm thinking of a number between

  13. #13
    Hyperactive Member barrk's Avatar
    Join Date
    Sep 2000
    Location
    My own little world
    Posts
    274

    Unhappy Don't know what to say

    I'm sorry...I'm fresh out of ideas. Maybe there is someone who has more experience with Access that could help. All the changes work for me (I set my field data type to shortdate and tried to run it).

    Hope you find an answer.

  14. #14

    Thread Starter
    Hyperactive Member PJB's Avatar
    Join Date
    Aug 2000
    Location
    dunno at the moment
    Posts
    302
    Thanx for everything, I'm sure I'll find out it's some other stupid setting that i have wrong
    VB6.0 SP4
    Windows 2000
    I'm thinking of a number between

  15. #15
    Hyperactive Member barrk's Avatar
    Join Date
    Sep 2000
    Location
    My own little world
    Posts
    274

    Wink I guess I'm not out of ideas after all.

    Try this:

    Replace your tick marks with pound signs

    sqlstring = "Select * from GEService Where PayDate Between #" & Format(DateFrom, "mm/dd/yyyy") & "# and #" &
    Format(DateTo, "mm/dd/yyyy") & "#"

    Give it a shot...what have you got to lose but more socks


    [Edited by barrk on 10-04-2000 at 06:57 PM]

  16. #16

    Thread Starter
    Hyperactive Member PJB's Avatar
    Join Date
    Aug 2000
    Location
    dunno at the moment
    Posts
    302
    Have already tried that and got the error that said:
    Run-time Error '13'

    Type Mismatch

    think i'll just set the computer on fire
    VB6.0 SP4
    Windows 2000
    I'm thinking of a number between

  17. #17
    Hyperactive Member barrk's Avatar
    Join Date
    Sep 2000
    Location
    My own little world
    Posts
    274
    Why don't we just call it quits. Stop looking for socks and have a beer. Gotta go till tomorrow

  18. #18

    Thread Starter
    Hyperactive Member PJB's Avatar
    Join Date
    Aug 2000
    Location
    dunno at the moment
    Posts
    302
    thanx again...
    VB6.0 SP4
    Windows 2000
    I'm thinking of a number between

  19. #19
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Brooklyn NY USA
    Posts
    1,258
    The Way to do this is as follows

    code

    Datefrom = Cdate("your date string)
    Dateto = Cdate("Your Dateto String")

    .....("Select * From ???? Where MYDATE > #" & Datefrom & "# AND < #" & Dateto & "#;")

    /code

    Any Question Feel Free To contact me at [email protected]

  20. #20

    Thread Starter
    Hyperactive Member PJB's Avatar
    Join Date
    Aug 2000
    Location
    dunno at the moment
    Posts
    302
    For anyone interested this is what i finally got to work:
    Code:
    Dim DateFrom As String
    Dim DateTo As String
    
    DateFrom = CDate(mskFrom.Text)
    DateTo = CDate(mskTo.Text)
      sqlstring = "Select * from GEService Where PayDate Between #" & DateFrom & "# and #" & DateTo & "#"
        With cmd
            .ActiveConnection = cn
            .CommandType = adCmdText
            .CommandText = sqlstring
            .Execute
        End With
        
        With rs
            .ActiveConnection = cn
            .CursorLocation = adUseClient
            .Open cmd
        End With
       
       Dim q As Integer
       Dim intCtrl As Integer
       Dim x As Integer
       Dim z As Integer
       x = 0
       q = 0
       z = 0
    
       With DataReport6
       
       Set .DataSource = rs
       .DataMember = ""
       With .Sections("Section1").Controls
           For intCtrl = 1 To .Count
         If TypeOf .Item(intCtrl) Is RptLabel Then
                    .Item(intCtrl).Caption = rs.Fields(q).Name & " :"
                     q = q + 1
                End If
                If TypeOf .Item(intCtrl) Is RptTextBox Then
                    .Item(intCtrl).DataMember = ""
                    .Item(intCtrl).DataField = rs(z).Name
                    z = z + 1
                End If
        Next intCtrl
       End With
       .Refresh
       .Show
       End With
       Unload Me
    End Sub
    VB6.0 SP4
    Windows 2000
    I'm thinking of a number between

  21. #21
    Hyperactive Member barrk's Avatar
    Join Date
    Sep 2000
    Location
    My own little world
    Posts
    274

    Smile YEAH!!!!!!!!

    Glad to see you got it working! Sorry I couldn't solve it for you...got you close though.

  22. #22

    Thread Starter
    Hyperactive Member PJB's Avatar
    Join Date
    Aug 2000
    Location
    dunno at the moment
    Posts
    302
    Your help was greatly appreciated barrk!!!!
    VB6.0 SP4
    Windows 2000
    I'm thinking of a number between

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