ODBC vba Query problem

popfan

New Member
Joined
Jul 20, 2011
Messages
2
I am using the following function call to pull back information from a database and it keeps giving me an OBDC call fail. This is the first time I had to use an inner join in this format. Normally works all the time for any single table query. Also first time using MAX

Code:
Function getMAXPRO(LINE, ITEM) As String

    Dim rstRecordset As DAO.Recordset

    On Error GoTo errors
    'On Error GoTo trap

    openconnection
    sqlstatement = _
            "SELECT MAX(Table1.DSDEAL) FROM Table1 INNER JOIN Table2 on Table1.STR#=Table2.RSSTR# WHERE LINE='" & LINE & "' AND ITEM='" & ITEM & "' AND RSRGN# not in (1,2)"

    Set rstRecordset = db.OpenRecordset(sqlstatement, DAO.dbOpenSnapshot)

    'get the data
   getMAXPRO = rstRecordset.Fields(0).Value

    'close the connections and clean up
    rstRecordset.Close
    Set rstRecordset = Nothing

    GoTo noerrors

errors:
    MsgBox Error
noerrors:

End Function
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Forum statistics

Threads
1,224,597
Messages
6,179,808
Members
452,944
Latest member
2558216095

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top