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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

run-time error message 3001 when trying to open recordset?

Status
Not open for further replies.

kskinne

Technical User
Oct 8, 2004
169
US
I have the following code tied to a command button:
Code:
Private Sub cmdOK_Click()
'On Error Resume Next
'On Error GoTo Handler1:

glbLogonMsg = "User ID and/or password is incorrect - please re-enter your login information."
glbUserID = txtUser.Text
glbCurPwd = txtPwd.Text

Set glbADORS1 = New ADODB.Recordset
glbSqlStr1 = "SELECT ID, Number, Name, Password, LastUpdated, FailedLogonAttempts, ExemptEmployee, HasMgrAccess FROM Employee WHERE Number = " & glbUserID
glbADORS1.Open glbSqlStr1, glbADOConn1, adOpenForwardOnly, adLockReadOnly

glbEmployeeID = glbADORS1.Fields("ID")
glbEmployeeName = Trim(glbADORS1.Fields("Name"))
glbFailedLogons = glbADORS1.Fields("FailedLogonAttempts")
glbExempt = glbADORS1.Fields("ExemptEmployee")
glbMgrAccess = glbADORS1.Fields("HasMgrAccess")

If glbADORS1.Fields("Password").Value <> glbCurPwd Then
  Set glbADORS2 = New ADODB.Recordset
  glbSqlFailure = "UPDATE Employee SET FailedLogonAttempts = (FailedLogonAttempts + 1) WHERE Number = " & glbUserID
  glbADORS2.Open SqlFailure, glbADOConn1, adOpenForwardOnly, adLockPessimistic
  GoTo Handler1:
Else
  Select Case glbFailedLogons
    Case 1
      MsgBox "There was " & glbFailedLogons & " previous failed login attempt.", vbOKOnly, ""
    Case Is > 1
      MsgBox "There were " & glbFailedLogons & " previous failed login attempts.", vbOKOnly, ""
    Case Else
  End Select
  Set glbADORS2 = New ADODB.Recordset
  glbSqlSuccess = "UPDATE Employee SET FailedLogonAttempts = 0 WHERE Number = " & glbUserID
  glbADORS2.Open SqlSuccess, glbADOConn1, adOpenForwardOnly, adLockPessimistic
  If (Now - (glbADORS1.Fields("LastUpdated") + 90)) >= 0 Or glbADORS1.Fields("Password") = "system" Or glbADORS1.Fields("Password") = "password" Then
    frmNewPwd.Show 1
  End If
  GoTo Handler2:
End If

Handler1:
MsgBox glbLogonMsg, vbCritical, "Login Incorrect"
txtUser.SetFocus
Exit Sub

Handler2:
frmLogin.Hide
frmTimeClock.Show 1
Set glbADORS2 = Nothing

End Sub
I have another piece of code triggered when my userform is loaded, that connects to the database. I have commented out the error handling in the code, and when I run the code, Whenever it encounters the line:
Code:
glbADORS2.Open SqlFailure, glbADOConn1, adOpenForwardOnly, adLockPessimistic
Or the line:
Code:
glbADORS2.Open SqlSuccess, glbADOConn1, adOpenForwardOnly, adLockPessimistic
I am getting the following error:
Run-time error '3001': Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another.
I know that I am connecting successfully to the database, because my other recordset named glbADORs1 is opening without any errors. It's probably something simple I'm sure, but I've been staring at it too long now and I cannot figure out why - any ideas?

Thank you for your help,
Kevin
 
fyi, this is how I am setting up my DB connection
Code:
Private Sub Form_Load()
glbServer = "myserver"
glbDatabase = "mydatabase"
glbSA = "sa"
glbSAPwd = "database"
Set glbADOConn1 = New ADODB.Connection
glbConn1 = "Provider=SQLOLEDB.1;Password=" + Trim$(glbSAPwd) + ";Persist Security Info=True;User ID=" + Trim$(glbSA) + ";Initial Catalog=" + Trim$(glbDatabase) + ";Data Source=" + Trim$(glbServer)
glbADOConn1.Open glbConn1
End Sub

All my global variables are declared in a separate module

Thanks,
Kevin
 
oh boy, never mind - I see now what my problem was. I just had to replace 'SqlFailure' with 'glbSqlFailure', and 'SqlSuccess' with 'glbSqlSuccess' and then all worked fine. Sorry for the waste of time, but thanks if you took a look.

Kevin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top