Results 1 to 5 of 5

Thread: getting sql query from text statment

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2000
    Location
    bebenia, PA, USA
    Posts
    241
    the below code returns the value of a text box with a text query. I need to be able to take the result and make it not a string but a query to query the database. How do I do this?



    Dim strStartDate As String
    Dim strStartDateMonth As String
    Dim strEndDate As String
    Dim sql As String
    Dim A As String

    If cboMonth = "January" Then
    cboMonth = "1"

    If cboMonth = "February" Then
    cboMonth = "2"

    If cboMonth = "March" Then
    cboMonth = "3"

    If cboMonth = "April" Then
    cboMonth = "4"

    If cboMonth = "May" Then
    cboMonth = "5"

    If cboMonth = "June" Then
    cboMonth = "6"

    If cboMonth = "July" Then
    cboMonth = "7"

    If cboMonth = "August" Then
    cboMonth = "8"

    If cboMonth = "September" Then
    cboMonth = "9"

    If cboMonth = "October" Then
    cboMonth = "10"

    If cboMonth = "November" Then
    cboMonth = "11"

    If cboMonth = "December" Then
    cboMonth = "12"
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If
    End If

    A = Mid(cboYear.Text, 3, 2) 'get 94 from 1994
    strStartDate = Format("10/4/94", "dd mmm yyyy")
    strEndDate = Format("01 " & cboMonth & " " & cboYear, "dd mmm yyyy")
    If CDate(strStartDate) < CDate(strEndDate) Then
    txtDate.Text = "Select * " & "From Master " & "WHERE DATE_OPENED BETWEEN '" & strStartDate & "' and '" & strEndDate
    'Data1.RecordSource = txtDate.Text
    'Data1.RecordSource = "SELECT (*) from MASTER WHERE DATE_OPENED BETWEEN '" & strStartDate & "' and '" & strEndDate = Form2.MSFlexGrid1
    'txtDate.Text = sql
    Data1.RecordSource = sql
    'Data1.Recordset.MoveFirst
    Else
    txtDate.Text = "Records do not go back to: " & strEndDate
    End If
    Form3.Show

  2. #2
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658
    I am not sure of the syntax of the date for SQL queries, but when you probaly need to put " ' " marks around the string.

    eg.

    Code:
      strStartDate = "'" & strStartDate & "'"
      strEndDate = "'" & strEndDate & "'"
    Iain, thats with an i by the way!

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2000
    Location
    bebenia, PA, USA
    Posts
    241
    Im not sure what you mean; I already get a string as a return value; example: select from Master where Date_Opened between 09 May 2000 and 01 May 2000. But its just returned as text I need it to actually query.

  4. #4
    Fanatic Member Stevie's Avatar
    Join Date
    Mar 2000
    Location
    London, UK
    Posts
    565

    Thumbs up

    You have to put # either side of dates in queries instead of '.

    eg. #18/04/2000#

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Mar 2000
    Location
    bebenia, PA, USA
    Posts
    241
    where are you saying to do this as the date is a variable

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