Microsoft
Software
Hardware
Network
Question : Using ADO in VBA for Query with multiple parameters
I need to populate a recordset using ADO for a predefined MS Access Query. The query has four parameters relating to two query fields. THe first field is ContractID, six alphanumeric long defined as text. It must match a field on an open form (form1) or it must be Null. The second field is WS# number defined as Double. It must match a field on the same open form or be Null. Both fields must either match the open form fiields or both be Null. I need to move back and forth through the recordset so I need to use ADO (I know how to do this). I have been reading and reading and trying different code for two dalys now. "Need and example of ADO code that will work". Have tried the code below to just get it to read if one field matches but still no luck.
Dim strRecSrc As String, strCriteria, strCnn As String
Dim cnn As ADODB.Connection
Dim cmd As ADODB.Command
Dim prm As ADODB.parameter
strRecSrc = "Tqry_QuesAndAns"
Dim rs As ADODB.Recordset
Set cmd = New Command
cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandText = strRecSrc
cmd.CommandType = adCmdStoredProc
Set prm = cmd.CreateParameter
prm.Type = adVarWChar
prm.Size = 6
cmd.Parameters(0).Value = Forms![frm_SiteData]![Cont
ractID]
'Set prm = cmd.CreateParameter(WSprm,
adDouble, adParamInput)
'cmd.Parameters.Append prm
'cmd.Parameters(1).Value = Forms![frm_SiteData]![WS#]
rs.Open cmd
Answer : Using ADO in VBA for Query with multiple parameters
Where do you instantiate the recordset variable? I don't see a
Set rs = New ADODB.Recordset
line anywhere.
Random Solutions
Type DATE rejected in CREATE TABLE
Access 2007 - Query - String Manipulation - I need to cut delete the first two Characters in a Field based on criteria
Visual Studio 2008; Website project; bin folder now showing?
Form Design in Access 2007
Formula " “=SUMPRODUCT” fully function
what does 554 message refused mean?
auto log off and close forms if idle problem
Access VBA Code with Excel Object Save As just started generating the Automation Error - The server threw an exception.
Outlook VB Code Quit Working
Access Runtime Error