Modifying pass-through query at runtime

B

Brian

I need to send through this pass-through query to a DB2 database via ODBC:

UPDATE <StaticTableName> SET <StaticFieldName> = CAST(<OtherStaticFieldName>
AS BLOB) WHERE <StaticNameOfPrimaryKey> = <DataThatChangesAtRuntime>

Everything is static, including the ODBC connect string, except the last
item in the Where statement (DataThatChangesAtRuntime). How can I pass this
value to the pass-through query at runtime?

Or, alternatively, is there a way to place the entire pass-through SQL
statement in VBA, including the ODBC connect string?
 
B

Brian Wilson

Brian said:
I need to send through this pass-through query to a DB2 database via ODBC:

UPDATE <StaticTableName> SET <StaticFieldName> =
CAST(<OtherStaticFieldName>
AS BLOB) WHERE <StaticNameOfPrimaryKey> = <DataThatChangesAtRuntime>

Everything is static, including the ODBC connect string, except the last
item in the Where statement (DataThatChangesAtRuntime). How can I pass
this
value to the pass-through query at runtime?

Or, alternatively, is there a way to place the entire pass-through SQL
statement in VBA, including the ODBC connect string?


You can just modify the SQL property of the querydef. There is also a
..Connect property but if you say this doesn't need to be altered then you
can use the following function. I hope it is clear how you would call it:


Public Function DefineQuery(strQuery As String, _
strSQL As String) As Boolean

On Error GoTo Err_Handler

Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef

Set dbs = CurrentDb

Set qdf = dbs.QueryDefs(strQuery)

qdf.SQL = strSQL

DefineQuery = True

Exit_Handler:

If Not qdf Is Nothing Then
Set qdf = Nothing
End If

If Not dbs Is Nothing Then
Set dbs = Nothing
End If

Exit Function

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Function
 
B

Brian

Thanks. That did it.

Brian Wilson said:
You can just modify the SQL property of the querydef. There is also a
..Connect property but if you say this doesn't need to be altered then you
can use the following function. I hope it is clear how you would call it:


Public Function DefineQuery(strQuery As String, _
strSQL As String) As Boolean

On Error GoTo Err_Handler

Dim dbs As DAO.Database
Dim qdf As DAO.QueryDef

Set dbs = CurrentDb

Set qdf = dbs.QueryDefs(strQuery)

qdf.SQL = strSQL

DefineQuery = True

Exit_Handler:

If Not qdf Is Nothing Then
Set qdf = Nothing
End If

If Not dbs Is Nothing Then
Set dbs = Nothing
End If

Exit Function

Err_Handler:
MsgBox Err.Description, vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Function


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top