Hi there.
I have an Excel Worksheet that I have included a Data Validation List to. The list is populated with items for sale. What I would like, is to have the user select any item from the list, and the cost of the item should be updated accordingly. No, I read somewhere that I can use the Worksheet_change event to do this, but When I put in my code below, I get the following error: Compile error: User-defined type not defined on the following line:
Dim cn as ADODB.Connection
Any ideas on how to do this?
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cell As Range
Dim Item As String
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sql As String
Set cn = ozConnection()
Set rs = New ADODB.Recordset
Range("B22") = Item
sql = "Select Amount from Items WHERE ItemDescr = " & Item
rs.Open sql, cn
If Not rs.EOF Then
Range("CostItem") = rs!amount
End If
End If
I have an Excel Worksheet that I have included a Data Validation List to. The list is populated with items for sale. What I would like, is to have the user select any item from the list, and the cost of the item should be updated accordingly. No, I read somewhere that I can use the Worksheet_change event to do this, but When I put in my code below, I get the following error: Compile error: User-defined type not defined on the following line:
Dim cn as ADODB.Connection
Any ideas on how to do this?
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cell As Range
Dim Item As String
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sql As String
Set cn = ozConnection()
Set rs = New ADODB.Recordset
Range("B22") = Item
sql = "Select Amount from Items WHERE ItemDescr = " & Item
rs.Open sql, cn
If Not rs.EOF Then
Range("CostItem") = rs!amount
End If
End If