|
-
Jul 11th, 2006, 04:15 PM
#1
Thread Starter
Hyperactive Member
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.
-
Jul 11th, 2006, 04:22 PM
#2
Re: Variable in SQL Statement
rs.Open "Select Count(*) from tblData Where Type = '" & Tourney & "' and Entry = '" & Entry & "';"
-
Jul 11th, 2006, 04:31 PM
#3
Thread Starter
Hyperactive Member
Re: Variable in SQL Statement
gave me invalid syntax error
-
Jul 11th, 2006, 04:37 PM
#4
Re: Variable in SQL Statement
Remove the ; from just before the end (some databases want it, others dont).
-
Jul 11th, 2006, 04:54 PM
#5
Thread Starter
Hyperactive Member
Re: Variable in SQL Statement
rs.Open "Select Count(*) from tblData Where Type = '" & Tourney & "' and Entry = '" & Entry & "'"
stil getting an error, to many qoutas?
-
Jul 11th, 2006, 05:08 PM
#6
Re: Variable in SQL Statement
rs.Open "Select Count(*) AS CountRows from tblData Where [Type] = '" & Tourney & "' and [Entry] = '" & Entry & "'"
-
Jul 11th, 2006, 05:30 PM
#7
Thread Starter
Hyperactive Member
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.
-
Jul 13th, 2006, 03:26 AM
#8
Thread Starter
Hyperactive Member
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
?
-
Jul 13th, 2006, 06:44 AM
#9
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:
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.
-
Jul 13th, 2006, 02:36 PM
#10
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
-
Jul 13th, 2006, 02:57 PM
#11
Thread Starter
Hyperactive Member
Re: Variable in SQL Statement
yes tblData is the name of my table.
-
Jul 14th, 2006, 11:16 AM
#12
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
-
Jul 15th, 2006, 02:12 AM
#13
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.
-
Jul 15th, 2006, 05:33 AM
#14
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|