views:

533

answers:

1

I'm creating parameterized queries in Access and would like to call them from ADO code in a VBA module in Word. I'm not sure of the syntax, however, to call parameterized queries. Can't seem to find a good code reference online.

If I have qryGetRecordByFirstLast that accepts Firstname and Lastname as parms, how do I code this execute in ADO from a VBA module?

+1  A: 

Here are a few notes

'Set up a command object '
Set cmd = CreateObject ("ADODB.Command")
cmd.CommandType = 4 'adCmdStoredProc '
cmd.CommandText = "qryGetRecordByFirstLast"

'adVarWChar = 202'
'adParamInput=1'
set par=cmd.CreateParameter ("Firstname",202,1,1,strFirstname)
cmd.Parameters.Append par

set par=cmd.CreateParameter ("Lastname",202,1,1,strLastname)
cmd.Parameters.Append par

dbfile="C:\Docs\LTD.mdb")
Set objConn=CreateObject("ADODB.Connection")

cmd.ActiveConnection = objConn

Set rs = CreateObject ("ADODB.Recordset")
rs.Open cmd, , 0, 1 'adOpenForwardOnly, adLockReadOnly'

blnFound = False

If Not rs.EOF Then
    astrRecord = rs.GetRows()
    intRecFirst  = LBound(astrRecord , 2)
    intRecLast   = UBound(astrRecord , 2)

    blnFound = True
End If
Remou