be sure that there is a space in front of FROM and WHERE
Main Topics
Browse All TopicsI'm getting this error Run-Time error 3146 ODBC - Call failed when i try to run this code. I dont know what i'm doig wrong. The code worked until i changed the SQL query. I have pasted both, the difference is the first SQL query. pLease help.
Original Working Code.
Sub Fill_Invoice_Info()
Dim InvRS As Recordset
Dim RDRS As Recordset
Dim qdf As QueryDef
Set qdf = db.CreateQueryDef("")
qdf.Connect = "odbc;dsn=SQLServer;uid=Us
qdf.ReturnsRecords = True
SQL1 = "SELECT DISTINCT Participants.CustID, Participants.InvID, Invoice.PCode, Invoice.BadgeName, Invoice.Leadership "
SQL2 = "FROM Invoice INNER JOIN Participants ON Invoice.InvID = Participants.InvID;"
qdf.SQL = SQL1 & SQL2
Set InvRS = qdf.OpenRecordset(dbOpenSn
SQL1 = "SELECT DISTINCT Participants.CustID, Participants.InvID, Min(InvoiceTransaction.tra
SQL2 = "FROM Participants INNER JOIN InvoiceTransaction ON Participants.InvID = InvoiceTransaction.invid "
SQL3 = "GROUP BY Participants.CustID, Participants.InvID;"
qdf.SQL = SQL1 & SQL2 & SQL3
Set RDRS = qdf.OpenRecordset(dbOpenSn
For i = 2 To NumOfPart + 1
CurrCust = MT.Cells(i, CustIDCol).Value
Criteria = "CustID = """ & CurrCust & """"
InvRS.FindFirst Criteria
MT.Cells(i, InvStart).Value = InvRS.Fields(3).Value 'Field(3) is BadgeName
If Not (IsNull(InvRS.Fields(4).Va
If InvRS.Fields(4).Value = 1 Then MT.Cells(i, LCCol).Value = "Leadership Council"
End If
RDRS.FindFirst Criteria
MT.Cells(i, RDCol).Value = RDRS.Fields(2).Value 'Field(2) is RegDate
Next i
End Sub
New COde that doesnt work.
Sub Fill_Invoice_Info()
Dim InvRS As Recordset
Dim RDRS As Recordset
Dim qdf As QueryDef
Set qdf = db.CreateQueryDef("")
qdf.Connect = "odbc;dsn=SQLServer;uid=Us
qdf.ReturnsRecords = True
SQL1 = "SELECT DISTINCT Participants.CustID, Participants.InvID, Invoice.PCode, Invoice.BadgeName, [NewAttendance#1].[#conf attended]"
SQL2 = "FROM (Invoice INNER JOIN Participants ON Invoice.InvID = Participants.InvID) INNER JOIN [NewAttendance#1] ON Invoice.CustID = [NewAttendance#1].CustID"
SQL3 = "WHERE ((([NewAttendance#1].[#con
qdf.Sql = SQL1 & SQL2 & SQL3
Set InvRS = qdf.OpenRecordset(dbOpenSn
SQL1 = "SELECT DISTINCT Participants.CustID, Participants.InvID, Min(InvoiceTransaction.tra
SQL2 = "FROM Participants INNER JOIN InvoiceTransaction ON Participants.InvID = InvoiceTransaction.invid "
SQL3 = "GROUP BY Participants.CustID, Participants.InvID;"
qdf.Sql = SQL1 & SQL2 & SQL3
Set RDRS = qdf.OpenRecordset(dbOpenSn
For i = 2 To NumOfPart + 1
CurrCust = MT.Cells(i, CustIDCol).Value
Criteria = "CustID = """ & CurrCust & """"
InvRS.FindFirst Criteria
MT.Cells(i, InvStart).Value = InvRS.Fields(3).Value 'Field(3) is BadgeName
If Not (IsNull(InvRS.Fields(4).Va
If InvRS.Fields(4).Value = 1 Then MT.Cells(i, LCCol).Value = "Leadership Council"
End If
RDRS.FindFirst Criteria
MT.Cells(i, RDCol).Value = RDRS.Fields(2).Value 'Field(2) is RegDate
Next i
End Sub
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
SQL1 = "SELECT DISTINCT Participants.CustID, Participants.InvID, Invoice.PCode, Invoice.BadgeName, [NewAttendance#1].[#conf attended] /* HERE */ "
SQL2 = "FROM (Invoice INNER JOIN Participants ON Invoice.InvID = Participants.InvID) INNER JOIN [NewAttendance#1] ON Invoice.CustID = [NewAttendance#1].CustID /* HERE */ "
SQL3 = "WHERE ((([NewAttendance#1].[#con
Business Accounts
Answer for Membership
by: mrperfect75000Posted on 2004-11-18 at 10:53:09ID: 12617600
It highlights apshot)
Set InvRS = qdf.OpenRecordset(dbOpenSn
has the culprit. I have no clue why.