Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL in vba

Status
Not open for further replies.

TheVicar75

Technical User
May 8, 2008
2
BE
Hi, i've got an sql statement that doesn't work.
I get runtime error 7874, what's wrong, all names are spelled correctly.

Private Sub cbo_SelectSupplier_AfterUpdate()
Dim StrSQL As String

StrSQL = "SELECT tbl_Demerit_0900_Overzicht_All.* "
StrSQL = StrSQL & " FROM tbl_Demerit_0900_Overzicht_All "
StrSQL = StrSQL & " WHERE tbl_Demerit_0900_Overzicht_All.RelationName = " & Forms!frm_Supplier_Evaluation!cbo_SelectSupplier & ");"

DoCmd.OpenQuery StrSQL


End Sub
 
You've got an end bracket at the end of your SQL without a matching start bracket.
Code:
Private Sub cbo_SelectSupplier_AfterUpdate()
    Dim StrSQL As String
    
    StrSQL = "SELECT tbl_Demerit_0900_Overzicht_All.* "
    StrSQL = StrSQL & " FROM tbl_Demerit_0900_Overzicht_All "
    StrSQL = StrSQL & " WHERE tbl_Demerit_0900_Overzicht_All.RelationName = " & Forms!frm_Supplier_Evaluation!cbo_SelectSupplier & ";"
    
    DoCmd.OpenQuery StrSQL
    
    
End Sub

hth

Ben

----------------------------------------------
Ben O'Hara
David W. Fenton said:
We could be confused in exactly the same way, but confusion might be like Nulls, and not comparable.
 
OpenQuery is designed to open a saved query that returns data (ie a select or union query).
To fix your problem, go to the queries tab, choose New, go to SQL view then paste the SQL code in.

SELECT tbl_Demerit_0900_Overzicht_All.*
FROM tbl_Demerit_0900_Overzicht_All "
WHERE tbl_Demerit_0900_Overzicht_All.RelationName = Forms!frm_Supplier_Evaluation!cbo_SelectSupplier

Save the query as qrySupplier.

Then, change the line to

DoCmd.OpenQuery "qrySupplier"

John
 
thx, i'll do it that way with the saved query.
i just thought there was another way...

thx
Vic.
 
Gak!
First day back in the TT saddle & I miss the problem!! Looks like I'm a little rustier than I thought!

B.

----------------------------------------------
Ben O'Hara
David W. Fenton said:
We could be confused in exactly the same way, but confusion might be like Nulls, and not comparable.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top