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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Joining a table from a list box in an SQL statement

Status
Not open for further replies.

sogen

Technical User
Jan 31, 2001
2
0
0
US
I am trying to join a table from a list box (Me!Combo) to another table in my SQL statement. I am getting an "Object doesn't support this property or method - error 438" The code works fine without the Join or Where clause. What am I missing?

Code:
Dim db As Database
Code:
Dim rst As Recordset
Code:
Dim strsql As String

Code:
strsql = "SELECT [Cost ctr], Grp([Cost ctr],[Cost ele]) AS Description, Sum([Value COCurr]) AS Total "
Code:
strsql = strsql & "FROM " & Me!Combo & " "
Code:
strsql = strsql & "INNER JOIN " & Me!Combo & " ON " & Me!Combo.[Cost ctr] & " = tblCost_ctr.Cost_ctr "
Code:
strsql = strsql & "WHERE ((([tblCost_ctr].[Org]) = " & Me!Combo23 & ")) "
Code:
strsql = strsql & "GROUP BY [Cost ctr], Grp([Cost ctr],[Cost ele]) "
Code:
strsql = strsql & "ORDER BY [Cost ctr], Grp([Cost ctr],[Cost ele]);"

Code:
Set rst = db.OpenRecordset(strsql)
 
Hi!
Point breakpoint one row after row which compose SQL for query, after program will be suspended on Immediate window ask for result of SQL expression (like >>> ?strSQL), then copy result and paste into SQL window of query constructor. Try to run query, then analise errors.

Aivars
 
If I understand this SQL string correctly then "Grp" is a custom function. If not, you should receive an error code "function grp not defined" as you try to execute this sql string.
Like Aivars I recommend that you just have a look at the string (simply use "msgbox strSql").
Another approach is copying this string into the sql window of the query grid.

Good luck and have a nice week-end!
 
Hi.

If the me!Combo is returning a string, you will need to enclose it in Single quotes for the statement to work.

Gzep.
 
I found and corrected a number of syntax errors and the code now runs fine. Thanks for your help!

Code:
strsql = "SELECT [" & Me!Combo & "].[Cost ctr], Grp([" & Me!Combo & "].[Cost ctr],[" & Me!Combo & "].[Cost ele]) AS Description, Sum([" & Me!Combo & "].[Value COCurr]) AS Total "
Code:
strsql = strsql & "FROM " & Me!Combo & " "
Code:
strsql = strsql & "INNER JOIN tblCost_ctr ON [" & Me!Combo & "].[Cost ctr] = tblCost_ctr.Cost_ctr "
Code:
strsql = strsql & "WHERE tblCost_ctr.Org = '" & Me!Combo23 & "' "
Code:
strsql = strsql & "GROUP BY [" & Me!Combo & "].[Cost ctr], Grp([" & Me!Combo & "].[Cost ctr],[" & Me!Combo & "].[Cost ele]) "
Code:
strsql = strsql & "ORDER BY [" & Me!Combo & "].[Cost ctr], Grp([" & Me!Combo & "].[Cost ctr],[" & Me!Combo & "].[Cost ele]);"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top