Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to "set" objects once only

Status
Not open for further replies.

duanecwilson

Programmer
Jul 15, 2005
26
US
I have several different controls on a form that refer to another form's combobox. I was setting it fresh in many different procedures and event procedures. I thought to, like private variables for the module to set them also once in the declaration section, and was able to Dim them, but I couldn't "set" them as "set" wasn't valid outside of a procedure. I was given an idea to do it in a separate procedure, function, or class, but haven't been able to do it. It seems simple, I just want to set it once and forget it. I would like to learn how to do it in a class module if possible (property get, let, etc.) but wouldn't mind it being in a procedure or function. Here is some code I have used but it doesn't work:

Option Compare Database
Option Explicit
'This is the column number from the combobox in Wave1Select that contains SRC_CUST_ID
Public intSrcCustIDidx As Integer
Dim frm As Form
Set frm = Forms!frmWave1Select
Dim cboSelection As Control
Set cboSelection = frm!cboWave1Select
Dim modcancel As Boolean
Dim strSRC_CUST_ID As String
-------------------------
Private Sub .... etc.
...
...
End Sub
-------------------------


I am not sure of the scope of the set statement. I don't know if I can set it and retrieve it in a standard module, a class module, or just the form's module. And I don't know if I could or should do it global. Thanks for any help here.


Duane Wilson
 
Can you create a module and just declare public varibles to hold the data.

Public strMyValue

Then you can put the value of your combo boxes into this public variable and call it from anywhere in the application.

ProDev, MS Access Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 



Hi,

"I am not sure of the scope of the set statement"

The Set statement has no scope. Set, assigns an object reference to a variable. It is how you declare your variables that defines the scope.

Skip,

[glasses] When a diminutive clarvoyant had disappeared from detention, headlines read...
Small Medium at Large[tongue]
 
So, does that mean that if I dimension them in the top declarations, and then set them once somewhere in the code that they will retain that reference until it is changed somewhere else?

Duane Wilson
 




If the SCOPE of your declaration includes all the procedures in which you use these variables.

Skip,

[glasses] When a diminutive clarvoyant had disappeared from detention, headlines read...
Small Medium at Large[tongue]
 
Thank you. I think I have done that. Now, I must figure out why things that were working before this seemingly small change are not working now. For instance, I am now getting a 2455 Error (You entered an expression that has an invalid reference to the property |. The property may not exist or may not apply to the object you specified.) when setting form fields = to recordset values. If you have any ideas, let me know. Otherwise, thanks anyway for the help.

Duane Wilson
 




Please post the code in context up to and including the statement that errors.

Skip,

[glasses] When a diminutive clarvoyant had disappeared from detention, headlines read...
Small Medium at Large[tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top