Solved

4 table join in VB6 MS access

Posted on 2009-04-01
6
347 Views
Last Modified: 2012-05-06
I've been doing some looking and have found a number of topics that address my issue of joining 4 tables from an MS access db in VB6 but none work.  I still get a "too few parameters, 1 expected" error.  It's driving me crazy.  I've put the latest code below but it still gives me that error.  I feel I've been in a big circle.

Can anyone point out what I'm doing wrong?

Thanks,
bob...
======
P.S. I didn;t know how to go back and add to my previous question so I added a new one here.
strsql = "SELECT [Qualifications].*, [QualificationCourses].*, [Roster].*, [Arms].* "

        strsql = strsql & " FROM ((( Qualifications "

        strsql = strsql & " INNER JOIN QualificationCourses ON Qualifications.[CourseID] = QualificationCourses.[ID]) "

        strsql = strsql & " INNER JOIN Roster on Qualifications.[AgentID] = Roster.[ID])"

        strsql = strsql & " INNER JOIN Arms on Qualifications.[ArmsID] = Arms.[ID]) "

        strsql = strsql & " WHERE [Qualifications].License = '" & Trim(userAdminMOD.currentUser.license) & "'"

Open in new window

0
Comment
Question by:bob-hytekltd
6 Comments
 
LVL 41

Expert Comment

by:ralmada
Comment Utility
try like this
strsql = "SELECT [Qualifications].*, [QualificationCourses].*, [Roster].*, [Arms].* "

strsql = strsql & " FROM Qualifications "

strsql = strsql & " INNER JOIN QualificationCourses ON Qualifications.[CourseID] = QualificationCourses.[ID] "

strsql = strsql & " INNER JOIN Roster on Qualifications.[AgentID] = Roster.[ID]"

strsql = strsql & " INNER JOIN Arms on Qualifications.[ArmsID] = Arms.[ID] "

strsql = strsql & " WHERE [Qualifications].License = '" & Trim(userAdminMOD.currentUser.license) & "'"

Open in new window

0
 
LVL 65

Accepted Solution

by:
rockiroads earned 200 total points
Comment Utility
Cant see whats wrong with your sql. Maybe fault is elsewhere where you are using this sql. Might be worth posting how you run this sql. Also, did you step thru the code to find the exact line where it is failing?

FYI
Another way, one I prefer over inner joins is to simply list the tables then perform the joins using the where clause
eg

strsql = "SELECT Qualifications.*, QualificationCourses.*, Roster.*, Arms.* "
strsql = strsql & " FROM Qualifications, QualificationCourses, Roster, Arms "
strsql = strsql & " WHERE Qualifications.CourseID = QualificationCourses.ID "
strsql = strsql & " AND Qualifications.AgentID = Roster.ID"
strsql = strsql & " AND Qualifications.ArmsID = Arms.ID "
strsql = strsql & " AND Qualifications.License = '" & Trim(userAdminMOD.currentUser.license) & "'"


select columns
from
where table1.somefield = table2.somefield
and table1.somefield = table3.somefield

etc
0
 
LVL 28

Assisted Solution

by:TextReport
TextReport earned 200 total points
Comment Utility
The error "too few parameters, 1 expected" implies you have a typo in one of the field names you have specified in the SQL so triple check each field in each table mentiones, specifically whatching out for spaces etc.

If you can take the result of the SQL into Access and paste into a queries SQL view and it will tell your there when you run it which field it doesn't like as it will as you for a value for it.

Cheers, Andrew
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 41

Assisted Solution

by:ralmada
ralmada earned 100 total points
Comment Utility
yeah, check your column names. there must be some misspelling in there.
0
 

Author Closing Comment

by:bob-hytekltd
Comment Utility
Thanks to all that replied.  The problem was in the spelling of one of the field names (I've only been writing this code for 18 years) but the suggestion to not use INNER JOINS was brilliant and I learned a new way of creating SQL statements this way.  A LOT simplier!!!  Thanks again everyone.  Experts Exchange is great... and so are all of the experts who participate!!!
Best to All!
bob...
======
0
 

Author Comment

by:bob-hytekltd
Comment Utility
In case you all didn't catch my humor... I misspelled "simpiler".
Best,
bob...
=======
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now