Computing.Net > Forums > Programming > Access 2003 & query parameters

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Access 2003 & query parameters

Reply to Message Icon

Name: wclairmont
Date: June 24, 2005 at 07:24:57 Pacific
OS: 2000
CPU/Ram: P4 1.8/512
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: StuartS
Date: June 24, 2005 at 08:16:08 Pacific
Reply:

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


0

Response Number 2
Name: wclairmont
Date: June 24, 2005 at 14:14:31 Pacific
Reply:

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, 1

If 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.Close

Any ideas?

Wade


0

Response Number 3
Name: StuartS
Date: June 24, 2005 at 14:34:42 Pacific
Reply:

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_id

If there were only one table in the FROM clause, they are not need in the WHERE clause.


Stuart


0

Response Number 4
Name: wclairmont
Date: June 24, 2005 at 15:14:27 Pacific
Reply:

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


0

Response Number 5
Name: StuartS
Date: June 24, 2005 at 16:46:58 Pacific
Reply:

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


0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon

Attn' Programming forum m... VB Data/Read Command?



Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Access 2003 & query parameters

Strange Access 2003 Problem www.computing.net/answers/programming/strange-access-2003-problem/10649.html

Import files into Access 2003 www.computing.net/answers/programming/import-files-into-access-2003/16680.html

SQL/Ms-Access Parameter Query www.computing.net/answers/programming/sqlmsaccess-parameter-query/10691.html