Article ID: 181716
Article Last Modified on 3/2/2005
Query Name Table Criteria On Field Datatype ------------------------------------------------------------------- ProductsByID Products [ProductID] ProductID Integer CustomerByID Customers [CustomerID] CustomerID TextMake sure you also set the parameter name and datatype in Microsoft Access 97. From the Query menu, choose Parameters. Create each query with three fields.
Button Name Caption
-------------------------------------
Command1 Command1 ProductsByID
Command2 Command2 CustomerByID
Dim Conn As New ADODB.Connection
Dim Cmd1 As New ADODB.Command
Dim Cmd2 As New ADODB.Command
Dim Rs As New ADODB.Recordset
Private Sub Form_Load()
Dim strConn As String
strConn = "DSN=Access97;"
With Conn
.CursorLocation = adUseClient
.ConnectionString = strConn
.Open
End With
End Sub
Private Sub Command1_Click()
With Cmd1
Set .ActiveConnection = Conn
.CommandText = "ProductsByID"
.CommandType = adCmdStoredProc
End With
Cmd1.Parameters.Refresh
Cmd1.Parameters(0).Type = adInteger
Cmd1.Parameters(0) = 3 'Set the numeric parameter value.
Rs.Open Cmd1, , adOpenStatic, adLockReadOnly
Debug.Print Rs(0), Rs(1), Rs(2)
Rs.Close
End Sub
Private Sub Command2_Click()
With Cmd2
Set .ActiveConnection = Conn
.CommandText = "CustomerByID"
.CommandType = adCmdStoredProc
End With
Cmd2.Parameters.Refresh
Cmd2.Parameters(0).Type = adVarChar
Cmd2.Parameters(0) = "COMMI" 'Set the text parameter value.
' If the next line is omitted you will get an error 3708 -
' "The application has improperly defined a Parameter Object".
Cmd2.Parameters(0).Size = 5
Rs.Open Cmd2, , adOpenStatic, adLockReadOnly
Debug.Print Rs(0), Rs(1), Rs(2)
Rs.Close
End Sub
Run the example and click the CustomerByID button. The Debug window
displays the returned values. Comment the Cmd2.Parameters(0).Size = 5 line
and rerun the example. The error occurs. 181782 HOWTO: Work with Access Querydef Parameter Using VB
175018 HOWTO: Acquire and Install the Microsoft Oracle ODBC Driver
Keywords: kbdatabase kbprb kbcode KB181716