ADODB Doesn't work when i call it from other events

T

tapan82

HELP! HELP! HELP!

I'm working on a project and have defined the following connection and
recordset in the Load event of the Form but when I click on the Save
button on the same form to save the data to the table using the
recordset it gives me an error saying "Compile error: Variable not
defined". I don't know why the connection and recordset is not
accessible when called from other events.


Load_Form
Dim Con As New ADODB.Connection
Dim Rst As New ADODB.Recordset
Set Con = CurrentProject.AccessConnection
Rst.ActiveConnection = Con
Rst.Source = "Select * from Master"
Rst.LockType = adLockOptimistic
Rst.CursorType = adOpenKeyset
Rst.Open
Set Me.Recordset = Rst

Save_Click
Rst![LIEN STATUS] = "WORK IN PROGRESS"
Me.txtLien = "WORK IN PROGRESS"
 
P

Pieter Wijnen

a variable is only available in it's scope (in your case the Form Load
Procedure)
ie you should move the declaration to the general section of the form

HTH

Pieter
 
T

tapan82

a variable is only available in it's scope (in your case the Form Load
Procedure)
ie you should move the declaration to the general section of the form

HTH

Pieter




HELP! HELP! HELP!
I'm working on a project and have defined the following connection and
recordset in the Load event of the Form but when I click on the Save
button on the same form to save the data to the table using the
recordset it gives me an error saying "Compile error: Variable not
defined". I don't know why the connection and recordset is not
accessible when called from other events.
Load_Form
Dim Con As New ADODB.Connection
Dim Rst As New ADODB.Recordset
Set Con = CurrentProject.AccessConnection
Rst.ActiveConnection = Con
Rst.Source = "Select * from Master"
Rst.LockType = adLockOptimistic
Rst.CursorType = adOpenKeyset
Rst.Open
Set Me.Recordset = Rst
Save_Click
Rst![LIEN STATUS] = "WORK IN PROGRESS"
Me.txtLien = "WORK IN PROGRESS"- Hide quoted text -

- Show quoted text -

I tried putting the code in the common place below Option Explicict
but i'm getting the following error when i open the form:

The expression On Open you entered as the event property setting
produced the following error: Invalid outside procedure.

*The expression may not result in the name of a macro, the name of a
user-defined, or [Event Procedure].
*There may have been an error evaluating the function, event or macro
 
P

Pieter Wijnen

Only The Dim Statements
ie
Dim Con As New ADODB.Connection
Dim Rst As New ADODB.Recordset

HTH

Pieter

a variable is only available in it's scope (in your case the Form Load
Procedure)
ie you should move the declaration to the general section of the form

HTH

Pieter




HELP! HELP! HELP!
I'm working on a project and have defined the following connection and
recordset in the Load event of the Form but when I click on the Save
button on the same form to save the data to the table using the
recordset it gives me an error saying "Compile error: Variable not
defined". I don't know why the connection and recordset is not
accessible when called from other events.
Load_Form
Dim Con As New ADODB.Connection
Dim Rst As New ADODB.Recordset
Set Con = CurrentProject.AccessConnection
Rst.ActiveConnection = Con
Rst.Source = "Select * from Master"
Rst.LockType = adLockOptimistic
Rst.CursorType = adOpenKeyset
Rst.Open
Set Me.Recordset = Rst
Save_Click
Rst![LIEN STATUS] = "WORK IN PROGRESS"
Me.txtLien = "WORK IN PROGRESS"- Hide quoted text -

- Show quoted text -

I tried putting the code in the common place below Option Explicict
but i'm getting the following error when i open the form:

The expression On Open you entered as the event property setting
produced the following error: Invalid outside procedure.

*The expression may not result in the name of a macro, the name of a
user-defined, or [Event Procedure].
*There may have been an error evaluating the function, event or macro
 
T

tapan82

Only The Dim Statements
ie
Dim Con As New ADODB.Connection
Dim Rst As New ADODB.Recordset

HTH

Pieter




a variable is only available in it's scope (in your case the Form Load
Procedure)
ie you should move the declaration to the general section of the form
HTH
Pieter

HELP! HELP! HELP!
I'm working on a project and have defined the following connection and
recordset in the Load event of the Form but when I click on the Save
button on the same form to save the data to the table using the
recordset it gives me an error saying "Compile error: Variable not
defined". I don't know why the connection and recordset is not
accessible when called from other events.
Load_Form
Dim Con As New ADODB.Connection
Dim Rst As New ADODB.Recordset
Set Con = CurrentProject.AccessConnection
Rst.ActiveConnection = Con
Rst.Source = "Select * from Master"
Rst.LockType = adLockOptimistic
Rst.CursorType = adOpenKeyset
Rst.Open
Set Me.Recordset = Rst
Save_Click
Rst![LIEN STATUS] = "WORK IN PROGRESS"
Me.txtLien = "WORK IN PROGRESS"- Hide quoted text -
- Show quoted text -
I tried putting the code in the common place below Option Explicict
but i'm getting the following error when i open the form:
The expression On Open you entered as the event property setting
produced the following error: Invalid outside procedure.
*The expression may not result in the name of a macro, the name of a
user-defined, or [Event Procedure].
*There may have been an error evaluating the function, event or macro- Hide quoted text -

- Show quoted text -

its working now! thank you so much for all the help

from Morning i have asked atleast 10 people about it but there was
nobody to come to help me.
i'm really thankful to you and google group for making my job easy.
thanks again!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top