Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am attempting to run a query in access 2003 passing a parameter from a publicly delcared variable, but to no avail.
Here is the query:
strsql = "SELECT a.tech_id, a.tech_first_name, a.tech_last_name, a.tech_start_date " & _
"FROM tech a, points b WHERE a.tech_status = 'Active', a.tech_id = b.points_tech_id " & _
"AND a.tech_id = " & declaration.login_tech_id & ";"declaration.login_tech_id - is the public string that I am tring to pass into the query, but it does not retain the value when the query is executed.
Anyone out there have any ideas, cause I am sure my formatting is wrong, but I am unable to find any examples else where.
Thanks for any help you can give!
Wade

The Where clause doesn't look right. This is supposed to be a table name or names. If you are selecting data from two different table names then you need to rethink the whole thing. You need to be looking at the JOIN statement.
The WHERE clause is a bit of a mess as well. Each comparison should be linked with AND or OR or combinations of the two..
a.tech_status = 'Active', a.tech_id = b.points_tech_id
This is all screwed up as well. a,tech_id means the field called tech_id in the table called a. Unless you have a table called a it is meaningless.
An SQL statement isn't terminated with a colon.
In fact the whole thing is a mess. You need to read up on SQL and differentiate between field names and table names and how to link the two.
Stuart

Stuart, you are right! I should have given you a copy of the SQL instead of trying to retype it fast. I got the parameter thing resolved, but now another problem....
Using a listbox in a form and trying to populate from VB. Listbox setup with 4 columns, row source from value list. Using the following code, the listbox presents with no content.
strsql = "SELECT a.tech_id, a.tech_first_name, a.tech_last_name, a.tech_start_date " & _
"FROM tech a, points b " & _
"WHERE a.tech_status = 'Active' " & _
"AND a.tech_id = b.tech_id " & _
"AND a.tech_id = " & declarations.login_tech_id & ";"
rst.Open strsql, con, 1If rst.EOF Then
Else
Do Until rst.EOF
Me.List16.AddItem CStr(rst!Tech_id)
Me.List16.AddItem CStr(rst!tech_first_name)
Me.List16.AddItem CStr(rst!tech_last_name)
Me.List16.AddItem CStr(rst!tech_start_date)
rst.MoveNext
Loop
End If
rst.CloseAny ideas?
Wade

Its not much different than before. Do you really have tables called called tech a, points b,a,b and declarations. You're still terminating the stament with a colon.
Any table names that appear in the WHERE clause (a,b,delcarations) also have to appear in the FROM (tech a, points b) clause. Like so
SELECT FROM Table1, Table2 WHERE Table1.tech_status = 'Active' _
AND Table1.tech_id = Table2.tech_id & _
AND Table1.tech_id = anothertable.login_tech_idIf there were only one table in the FROM clause, they are not need in the WHERE clause.
Stuart

I have tables tech & points. A & B are assigned to tech & points respectively as references. Declarations is the module where the public variables are declared and DECLARATIONS.LOGIN_TECH_ID is the parameter that I was trying to pass to the query(this issue I have already resolved). What I need help on is how do I populate a multi-column listbox from a recordset?
Any ideas?
Wade

Set the columns property to the number of columns you need.
List1.Columns = 4
However the columns fill from top to bottom and left to right.
I always found it easier and more flexible to use the MSFlex Grid for displaying data in an ordered fashion.
Stuart

![]() |
Attn' Programming forum m...
|
VB Data/Read Command?
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |