I have a trouble with the Listview1 when i try to select the category it says "Variable not defined". i put all the necessary references and components. Perhaps i've overlooked some code that needs to be in the project. Can somebody check this for me please...
Here's the code:
Option Explicit
Dim RS_CAT_SEL As New ADODB.Recordset
Private Sub Command1_Click()
If ListView1.ListItems.Count < 1 Then Unload Me: Exit Sub
select_rec
End Sub
Sub select_rec()
With rs_employee_ae ' this code highlights the error
.Cat_Index = ListView1.SelectedItem.ListSubItems(1)
.Text3.Text = ListView1.SelectedItem.ListSubItems(2)
End With
Unload Me
End Sub
Private Sub Command13_Click()
Unload Me
End Sub
Private Sub Form_Load()
RS_CAT_SEL.Open "SELECT * FROM tblCategory ORDER BY CategoryName ASC", CN, adOpenStatic, adLockReadOnly
Load_Rec
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set RS_CAT_SEL = Nothing
End Sub
Sub Load_Rec()
Screen.MousePointer = vbHourglass
I have a trouble with the Listview1 when i try to select the category it says "Variable not defined".
Code:
Dim RS_CAT_SEL As New ADODB.Recordset
Private Sub Command1_Click()
If ListView1.ListItems.Count < 1 Then Unload Me: Exit Sub
select_rec
End Sub
Sub select_rec()
With rs_employee_ae ' this code highlights the error
.Cat_Index = ListView1.SelectedItem.ListSubItems(1)
.Text3.Text = ListView1.SelectedItem.ListSubItems(2)
End With
Unload Me
End Sub
I'm not sure what rs_employee_ae is here but it is not defined just like the error message tells you.
The rs at the begining makes me think it is intended to be a recordset object but then you are refereencing the .text3.text which makes it look like it is a poorly named form object.
At any rate when you get an error tellign you Variable not defined it means that either you did not define the variable it is showing you or you have misspelled it. Pretty obovious really.
i have this code declared in PUBLIC in the other form (form1) "rs_employee_ae".
Here it is:
Option Explicit
Public add_state As Boolean
Public rs_employee_ae As New ADODB.Recordset
Public Old_ID As String
Public UPDATE_USER As Boolean
Public Cat_Index As Long
With rs_employee_ae ' this code highlights the error
.Cat_Index = ListView1.SelectedItem.ListSubItems(1)
.Text3.Text = ListView1.SelectedItem.ListSubItems(2)
End With
If the var is defined as public in a different form then you must specify the formname as well.
e.g.
Code:
With Form1.rs_employee_ae
It would make more sense to declare the variable in a module if it truly needs to be public.
Of course the next 2 lines are also going to generate errors as they are not properties of the recordset but appear to be objects on your other form.
Look carefully at your code and you should see your mistakes, also remember that you must always specifiy the form name when trying to access items of a form from any source other than the form where they reside.
Last edited by DataMiser; February 4th, 2012 at 02:07 AM.
Bookmarks