Hello,
Can anyone help me out with my problem.
The following code, that i have aquired, finds a record in a table based on the information put into a text box, then outputs the" last name" value from that row of the table.
Private Sub cmdFindRecord_Click()
Dim adoRst As ADODB.Recordset
Dim txtEmpID As TextBox
Dim txtLastName As TextBox
Dim lngValue As Long
Set adoRst = New ADODB.Recordset
adoRst.ActiveConnection = CurrentProject.Connection
adoRst.Open "Employees", , adOpenDynamic, adLockOptimistic
lngValue = Me.txtEmpID.Value
adoRst.Find ("EmployeeID = " & lngValue)
Me.txtLastName.Value = adoRst("LastName")
adoRst.Close
Set adoRst = Nothing
End Sub
I am trying to adapt this code to work after update of a combo box containing a drop down of all my equipments, and produce the serialnumber that represents that equipment.
The combo box is sourced from the column that i am asking the code to find through - is this an issue?
My table has no primary key defined...it is a list of equipment and serial numbers - is this an issue?
The following is my attempt.
Private Sub cboEquipmentType_AfterUpdate()
Dim adoRst As ADODB.Recordset
Dim cboEquipmentType As ComboBox
Dim txtSN As TextBox
Dim strEqpt As String
Set adoRst = New ADODB.Recordset
adoRst.ActiveConnection = CurrentProject.Connection
adoRst.Open "tbl_SN", , adOpenDynamic, adLockOptimistic '
strqpt = Me.cboEquipmentType.Value
adoRst.Find ("[EquipmentDescription] = " & strEqpt)
Me.txtSN.Value = adoRst("SN")
adoRst.Close
Set adoRst = Nothing
End Sub
The code stalls at the highlighted line and brings 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 am at a complete dead end with this problem, and very much a beginner with vba. Any help either with my code or a solution to what im trying to achieve would be greatly appretiated.
Cheers
Dan
Can anyone help me out with my problem.
The following code, that i have aquired, finds a record in a table based on the information put into a text box, then outputs the" last name" value from that row of the table.
Private Sub cmdFindRecord_Click()
Dim adoRst As ADODB.Recordset
Dim txtEmpID As TextBox
Dim txtLastName As TextBox
Dim lngValue As Long
Set adoRst = New ADODB.Recordset
adoRst.ActiveConnection = CurrentProject.Connection
adoRst.Open "Employees", , adOpenDynamic, adLockOptimistic
lngValue = Me.txtEmpID.Value
adoRst.Find ("EmployeeID = " & lngValue)
Me.txtLastName.Value = adoRst("LastName")
adoRst.Close
Set adoRst = Nothing
End Sub
I am trying to adapt this code to work after update of a combo box containing a drop down of all my equipments, and produce the serialnumber that represents that equipment.
The combo box is sourced from the column that i am asking the code to find through - is this an issue?
My table has no primary key defined...it is a list of equipment and serial numbers - is this an issue?
The following is my attempt.
Private Sub cboEquipmentType_AfterUpdate()
Dim adoRst As ADODB.Recordset
Dim cboEquipmentType As ComboBox
Dim txtSN As TextBox
Dim strEqpt As String
Set adoRst = New ADODB.Recordset
adoRst.ActiveConnection = CurrentProject.Connection
adoRst.Open "tbl_SN", , adOpenDynamic, adLockOptimistic '
strqpt = Me.cboEquipmentType.Value
adoRst.Find ("[EquipmentDescription] = " & strEqpt)
Me.txtSN.Value = adoRst("SN")
adoRst.Close
Set adoRst = Nothing
End Sub
The code stalls at the highlighted line and brings 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 am at a complete dead end with this problem, and very much a beginner with vba. Any help either with my code or a solution to what im trying to achieve would be greatly appretiated.
Cheers
Dan