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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking state of a control

Status
Not open for further replies.

idd

Programmer
Apr 19, 2002
165
GB
All,

I am trying to be more efficient with my code by using global modules.

What I want to do is....

I have a form where there are approx 6 text boxes. 5 of them have a tag value of 1 the other text box has a tag value of 6.

When the form moves from one record to another, tag 1's become

locked =true
enabled = false

tag 2 becomes locked = true
default for enabled = true so that user can read and scroll

I have a button which allows edits.

When the button is pressed it enables all tag 1's and tag 2
and locked becomes false on all of them.

It all works fine, but what I want to do is.

Keep the enabling = false and locking of the text boxes when the form moves from record to record.

the change i want to make is that if the user clicks on the edit button it allows edits and then if the user clicks on it again then it disables the edits, I'm sure I could use a toggle button, button I just want to use a command button, with code behind it which makes a module call which will first check if the tag '1 are enabled = true and locked = false

the code in the module needs to

check enabled status of A text box with property tag = 1
if it is enabled = false then it returns a boolean of false

else true.

The code behind the button would call the module, get the result of false and then allow edits otherwise it would get the result of false and disable edits.

The problem is that when I am using a global Module I cant really say something like me.txtXX, it really needs to be able to find a txt box which has a tag value of 1 and then check its enabled state, before passing the boolean to the form.


To summarise, this one command button when clicked works both to allow edits or disables them.


Hope this makes sense n hope you can help.
Idd


 
The bad news is: You cannot reference "me" from a global module. "me" represents a shorthand way of referencing the current form or report, from within the code of the current form or report.

The good news is: The problem is easily addressed. In a global module, simply declare a Form control, and provide it a value. For example:

Dim F as Form
Set F = Forms!frmYourFormName

Now, instead of referencing "me.txtXX" (as per your post), you refer to the control as:

F!txtXX

Two other things to note:

(a) me.txtXX as you refer to the control is syntactically incorrect, as the dot convention means that what follows is a method. Use the "bang" character (ie. explanation) to prefix a control; ie.

me!txtXX or F!txtXX

(b) Its also good practice to use me as infrequently as possible in your code; this makes the code easily transferable between forms and global modules. For example, the following code is easily transferred to a global module:

...............
Dim F as Form
Set F = me 'This is the only reference to me
F!txtCtl1 = "this"
F!txtCtl2 = "that"
F!txtCtl3 = "the other"
...............

To make this code work in a global module, only the Set F = line needs to be changed, to explicitly declare the form.

Whereas, if me is referenced all over the place, then each instance needs to be changed when the code is moved.

Hope that helps you make progress,


Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
(dont cut corners or you'll go round in circles)
 
Why not just pass the 'me' object to any code that uses it as a parameters?

e.g.

function MyFunction(TheForm as form) as boolean
MyFunction = TheForm.name = "Blah"
end function

******************

private sub Form_Open()
MyFunction(Me)
end sub

 
Yes, if you take the stuff I mentioned to the next level, its even better to pass the form as an argument to the function, as suggested by beetee.


Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
(dont cut corners or you'll go round in circles)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top