Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parameter query only working first time.

Status
Not open for further replies.

Sypher2

Programmer
Oct 3, 2001
160
US
Hello,

I'm trying my hand at the Parameter collection to hopefully make repetitive queries easier. I have a list box of employees and I use the SSN as the parameter for a stored procedure. The query gets a number and puts it into a text box. The number is correct for the first query, but gives the same number for any subsequent queries.

Code:
Private Sub lstNames_Click()
Dim i As Long
    
    lblSSN.Caption = "": txtUns.Text = ""
    i = lstNames.ItemData(lstNames.ListIndex)
    lblSSN.Caption = Employee(i).SSN
    With cmd
        .CommandText = "_ParamAttendStats"
        .CommandType = adCmdStoredProc
        .Parameters("SocSecNum") = lblSSN.Caption
    End With
    rs.Open cmd, , adOpenStatic, adLockReadOnly
    txtUns.Text = rs.RecordCount
    rs.Close
    Set rs = Nothing
End Sub
I created the parameter and set the active connection in the Form_Load event.

Thanks for any help.
 
Should be this:

Private Sub lstNames_Click()
Dim i As Long
txtUns.Text = lstNames.Text
With cmd
.CommandText = "_ParamAttendStats"
.CommandType = adCmdStoredProc
.Parameters("SocSecNum") = txtUns.Text
End With
rs.Open cmd, , adOpenStatic, adLockReadOnly
rs.Close
Set rs = Nothing
End Sub
Thanks

Neo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top