Results 1 to 14 of 14

Thread: Variable in SQL Statement

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    300

    Variable in SQL Statement

    Code:
    Public Sub LoadStats(Tourney As String, Entry As String, Entrants As String)
    
    rs.Open "Select Count(*) from tblData Where Type = ' &Tourney& ' and Entry = ' &Entry& '"
    
    If Not rs.EOF Then
        Text1.Text = rs.Fields(0).Value
    End If
    
    End Sub
    i have three variables in my call but i can't seem to write them properly in the SQL box and getting fustrated because its probably simple.
    Im Learning !!!!

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Variable in SQL Statement

    rs.Open "Select Count(*) from tblData Where Type = '" & Tourney & "' and Entry = '" & Entry & "';"

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    300

    Re: Variable in SQL Statement

    gave me invalid syntax error
    Im Learning !!!!

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Variable in SQL Statement

    Remove the ; from just before the end (some databases want it, others dont).

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    300

    Re: Variable in SQL Statement

    rs.Open "Select Count(*) from tblData Where Type = '" & Tourney & "' and Entry = '" & Entry & "'"

    stil getting an error, to many qoutas?
    Im Learning !!!!

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Variable in SQL Statement

    rs.Open "Select Count(*) AS CountRows from tblData Where [Type] = '" & Tourney & "' and [Entry] = '" & Entry & "'"

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    300

    Re: Variable in SQL Statement

    Code:
    Public Sub LoadStats(Tourney As String, Entry As String, Entrants As String)
    
    rs.Open "Select Count(*) from tblData Where [Type] = '" & Tourney & "' and [Entry] = '" & Entry & "'"
    
    If Not rs.EOF Then
        Text1.Text = rs.Fields(0).Value
    End If
    
    End Sub
    calling it like this

    Code:
    Private Sub Command1_Click()
        Call LoadStats(Combo1.Text, Combo2.Text, Combo3.Text)
    End Sub
    and i get this error

    Run-time error '-2147217900(80040e14)':
    Syntax error in FROM clause.


    Im Learning !!!!

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    300

    Re: Variable in SQL Statement

    Someone must know where it is wrong? it can't be that much wrong.

    Code:
    Public Sub LoadStats(Tourney As String, Entry As String, Entrants As String)
    
    rs.Open "Select Count(*) from tblData Where Type = '" & Tourney & "' and Entry = '" & Entry & "'"
    
    If Not rs.EOF Then
        Text1.Text = rs.Fields(0).Value
    End If
    
    End Sub
    ?
    Im Learning !!!!

  9. #9
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Variable in SQL Statement

    As the error is "Syntax error in FROM clause.", the issue seems to be with the table name.. but I can't see why that would be.

    Try this:
    VB Code:
    1. rs.Open "SELECT Count(*) AS CountRows FROM [tblData] WHERE [Type] = '" & Tourney & "' and [Entry] = '" & Entry & "'"

    If there are still problems, let us know what is in the Tourney and Entry variables.

  10. #10
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Variable in SQL Statement

    You're not using tblData as your table name, are you?
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2005
    Posts
    300

    Re: Variable in SQL Statement

    yes tblData is the name of my table.
    Im Learning !!!!

  12. #12
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Variable in SQL Statement

    Okay - it's what I would expect as an example name.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  13. #13
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Variable in SQL Statement

    just check spelling in the table name in your database...if you run the same code in access are you getting the results....
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  14. #14
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Variable in SQL Statement

    Run your statement in Query Analyzer. I don't understand what the syntax error is. Maybe you've spelt something wrong, but run it in Query Analyzer anywyas.

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