-
February 3rd, 2012, 03:16 PM
#1
Compile error: Variable not defined
Hi GUru's,
Good day!
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
Call FillListView(ListView1, RS_CAT_SEL, 3, 1, True, True)
Screen.MousePointer = vbDefault
If ListView1.ListItems.Count < 1 Then Command1.Caption = "&Close"
End Sub
Private Sub ListView1_DblClick()
select_rec
End Sub
-
February 3rd, 2012, 05:18 PM
#2
Re: Compile error: Variable not defined
Can't read it, plus a few basics:
Use CODE TAGS so we can read your code.
Point out the Error Line, and ERROR MESSAGE
And, then, we might be able to help
-
February 3rd, 2012, 06:39 PM
#3
Re: Compile error: Variable not defined
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.
Always use [code][/code] tags when posting code.
-
February 3rd, 2012, 07:49 PM
#4
Re: Compile error: Variable not defined
Here's an article, with sample code: here
It shows how to open query and close a table.
-
February 4th, 2012, 02:49 AM
#5
Re: Compile error: Variable not defined
DataMiser,
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
-
February 4th, 2012, 03:04 AM
#6
Re: Compile error: Variable not defined
Code:
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 03:07 AM.
Always use [code][/code] tags when posting code.
-
February 4th, 2012, 03:12 AM
#7
Re: Compile error: Variable not defined
DataMiser,
I've got your point and it's functioning now. (^_^)
Thank you.
-
February 4th, 2012, 03:16 AM
#8
Re: Compile error: Variable not defined
dglienna,
Thank you also.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|