Hi, I would like my combo box to response when a selection is pick. For my code below:
If CPT is selected from the combo, I would like to enquire from the Computer table and get the last record(its auto increment) and save it to a variable and increment it by 1, then display it to the screen. But i get Run-time error '3265': Item cannot be found in the collection corresponding to the requested name or ordinal. Can anyone explain to me why does this error occur corresponding to my code? Thank you.
Private Sub cboEqpType_Click()
Dim sCptCount As Integer
sCptCount = 0
If cboEqpType.Text = "CPT" Then
moCommand.CommandType = adCmdText
moCommand.ActiveConnection = moConnection
moCommand.CommandText = _
"SELECT MAX(CptID) FROM Computer;"
'Run the query
Set rsMain = moCommand.Execute
sCptCount = rsMain!CptID
sCptCount = sCptCount + 1
txtEDPControlNo = sCptCount
txtEDPControlNo.Enabled = False
cboEqpType.Enabled = False
End If
End Sub
If CPT is selected from the combo, I would like to enquire from the Computer table and get the last record(its auto increment) and save it to a variable and increment it by 1, then display it to the screen. But i get Run-time error '3265': Item cannot be found in the collection corresponding to the requested name or ordinal. Can anyone explain to me why does this error occur corresponding to my code? Thank you.
Private Sub cboEqpType_Click()
Dim sCptCount As Integer
sCptCount = 0
If cboEqpType.Text = "CPT" Then
moCommand.CommandType = adCmdText
moCommand.ActiveConnection = moConnection
moCommand.CommandText = _
"SELECT MAX(CptID) FROM Computer;"
'Run the query
Set rsMain = moCommand.Execute
sCptCount = rsMain!CptID
sCptCount = sCptCount + 1
txtEDPControlNo = sCptCount
txtEDPControlNo.Enabled = False
cboEqpType.Enabled = False
End If
End Sub