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

conditionally enabling/locking/coding controls on form 1

Status
Not open for further replies.

uscitizen

Technical User
Jan 17, 2003
672
US
I have two forms which we shall call 'E E' and 'L E' [note the use of spaces in the names here is deliberate] the one called 'L E' being nested within 'E E' using 'Patient Number'. 'E E' and 'L E' when viewed are listed as viewed as 'Single' and 'Continuous' forms respectively, just for the sake of thoroughness.

On the nested form there is a control called 'Visit' which uses a combo box as well as several others. When 'Visit' equals '0' I would like the following things to happen: I would like a bunch of the controls to be both locked and disabled and to take on certain values.

Is that doable?
 
Hi!

In the after update event of the visit control, you might try something like this

if me!visit=0 then
me!txtOne.loced=true
me!txtOne.enabled=false
me!txtTwo.locked=true
me!txtTwo.enabled=false
me!txtThree = "Some text"
'...
else
me!txtOne.loced=false
me!txtOne.enabled=true
me!txtTwo.enabled=true
me!txtThree = "Some other text"
'...
endif

You might wan't to add some test to verify that there is actually a value in visit, too

HTH Roy-Vidar
 
BTW - I'm assuming this is Access, and sorry for the two typos (loced -> locked)

 
Hi Roy!

Seems very straightforward to me. And don't worry about a fue typoe4 hear and their :)

I'm going to give it a try tomorrow when I gets back to 'the office' and let you know how it goes.

Say, not to change the topic, but it says 'Instructor' alongside your handle; what's a 'good' way to make VBA seem a little less intimidating.....I've been thinking about finding some 'online' (web based or CDROM) courseware?
 
Opinion: I feel that online/CD coursware are often creating more questions than answers. The excersises/tasks are seldom "identifiable" in manner of relevance to what you wish to achieve... bla bla bla

There are some other recomandations, including mine in thread705-670332 but I'll state it again and again, having an actual task is the best motivator I know of;-)

Roy-Vidar
 
Hi, I've cobbled in the code below based on the above 'template':

Private Sub Visit_AfterUpdate()
' locks and disables certain fields when the visit is at b/l

If Me!Visit = 0 Then
Me![Nontarget Lesions].Locked = True
Me![Nontarget Lesions].Enabled = False
Me![Nontarget Lesions] = "Absent"
Me![New Lesions].Locked = True
Me![New Lesions].Enabled = False
Me![New Lesions] = "N/A"
Me![Response].Locked = True
Me![Response].Enabled = False
Me![Response] = "N/A"
Else
Me![Nontarget Lesions].Locked = False
Me![Nontarget Lesions].Enabled = True
Me![New Lesions].Locked = False
Me![New Lesions].Enabled = True
Me![Response].Locked = False
Me![Response].Enabled = True
End If
End Sub

I wanted to say that it doesn't yet appear to be working and ask about the possible relevance of the fact that 'Visit' is a Combobox -- I didn't mention it in my original 'cause I didn't know, and that's why I'm writing.

In 'Visit' prop field, the row source type is specified to be 'Table/Query' and the row source is given thus:

SELECT [Look_Visit].[Visit], [Look_Visit].[Vis Name] FROM Look_Visit;

The column count is 2, the first column is not displayed (the second one is), the bound column property is specified to be '1' and the limit to list prop is a 'yes' just in case these matter. Column '1' has the values 0,......12 and 'Vis Name' (column 2) has textual labels, such as 'Baseline', .......'Follow Up 12'.
 
Hi, I've cobbled in the code below based on the above 'template':

Private Sub Visit_AfterUpdate()
' locks and disables certain fields when the visit is at b/l

If Me!Visit = 0 Then
Me![Nontarget Lesions].Locked = True
Me![Nontarget Lesions].Enabled = False
Me![Nontarget Lesions] = "Absent"
Me![New Lesions].Locked = True
Me![New Lesions].Enabled = False
Me![New Lesions] = "N/A"
Me![Response].Locked = True
Me![Response].Enabled = False
Me![Response] = "N/A"
Else
Me![Nontarget Lesions].Locked = False
Me![Nontarget Lesions].Enabled = True
Me![New Lesions].Locked = False
Me![New Lesions].Enabled = True
Me![Response].Locked = False
Me![Response].Enabled = True
End If
End Sub

I wanted to say that it doesn't yet appear to be working and ask about the possible relevance of the fact that 'Visit' is a Combobox -- I didn't mention it in my original 'cause I didn't know, and that's why I'm writing.

In 'Visit' prop field, the row source type is specified to be 'Table/Query' and the row source is given thus:

SELECT [Look_Visit].[Visit], [Look_Visit].[Vis Name] FROM Look_Visit;

The column count is 2, the first column is not displayed (the second one is), the bound column property is specified to be '1' and the limit to list prop is a 'yes' just in case these matter. Column '1' has the values 0,......12 and 'Vis Name' (column 2) has textual labels, such as 'Baseline', .......'Follow Up 12'.

Also, in case this has any bearing on the thread, the three fields we're talking about, "Nontarget Lesions", "New Lesions" and "Response" are each 'Combobox' types, and each uses a look-up table having one column.
 
Hi again!

When testing a combo's value by stating me!combo = "something", its the bound column which is being tested. In your case, that would be the '[Look_Visit].[Visit]' field.

If you're testing for another value then 0, just replace the 0 in the code with the new value.

To check how(if) it's working, try inserting a breakpoint on the line 'If Me!Visit = 0 Then' (If you're unfamiliar with how; right-click the line, select Toggle | Breakpoint). This should halt your code execution at that line. Try finding out what value me!visit has (hovering the mouse cursor over it should provide a label with the value, if not, select me!visit and hit F9) and compare it with the value it should have, according to the selection in the combo. Continue by i e hitting F8, to execute line by line (you can also try right click the line you would like to execute, set next statement, to make it the next line to be executed)

I'm seeing you have a control named Visit on your form, which is a combobox, and you have a field named Visit in the queries row source - I'm assuming the same field is also in the record source of the form (table or query), and maybe the control source for the combo?. When there's both a field in the forms recordsource and a control on the form using the same name (which is the case when using form wizards) Access, might get a litle confused by it. This might be the cause of your current challenge. Most developers use some kind of a naming convention prefixing their objects; table=tbl, query=qry, textbox=txt, combo=cbo, command button=cmb... Naming and prefixing controls in forms and reports are very important issues, when your'e going to manipulate them thru code - if not Access might give curious results.

Roy-Vidar
 
Hi, I thought I'd give your last reply a red star -- for effort -- even if it doesn't help unmuddy the waters (because, I'm going to assume I'm a newbie wrt VBA).

I renamed the 'Visit' field in the l/u table 'Look_Visit' to 'VisitNum' to differentiate and so we're now using

SELECT [Look_Visit].[VisitNum], [Look_Visit].[Vis Name] FROM Look_Visit;

This (hopefully) allows me to continue using the same code below:

Private Sub Visit_AfterUpdate()
' locks and disables certain fields when the visit is at b/l

If Me!Visit= 0 Then
Me![Nontarget Lesions].Locked = True
Me![Nontarget Lesions].Enabled = False
Me![Nontarget Lesions] = "Absent"
Me![New Lesions].Locked = True
Me![New Lesions].Enabled = False
Me![New Lesions] = "N/A"
Me![Response].Locked = True
Me![Response].Enabled = False
Me![Response] = "N/A"
Else
Me![Nontarget Lesions].Locked = False
Me![Nontarget Lesions].Enabled = True
Me![New Lesions].Locked = False
Me![New Lesions].Enabled = True
Me![Response].Locked = False
Me![Response].Enabled = True
End If
End Sub

I tried your suggestion wrt the breakpoint however it didn't seem to get anywhere.....after the selected line beginning with 'If.....' turned a redishbrown and a circle appeared to the left of the text, I tried hovering the cursor over it and waited and waited for some value to appear. It's not really your fault, but I don't quite understand the drift/thrust of the mechanics you described.
 
Oups - it's completely my foult for not explaining thouroghly enough (and totally unworthy of a star, but still, thanx).

The breakpoint thingie is something that makes the code stop executing, so try it again.

Then go back to Access open the form and select a value in the combobox.

After selecting a value in the combobox, the code on the combobox after update is supposed to start running. You are the supposed to be "thrown" over to the module, and the line with the breakpoint should be higlighet (even more).

Then it's possible to study the values in any variables in the code by either hovering the mouse cursor over them or as an alternative, select them and press not F9 as I stated previously, but SHIFT+F9 (sorry).

F5 - Run (all the code)
F8 - step line by line
F9 - toggle breakpoint
SHIFT + F9 - Quick watch on selected expression (viewing the value)
CTRL+SHIFT+F9 - Clear all breakpoints

Roy-Vidar
 
Sort of like watching a B-movie in a cheap motel along the favorite fwy truckers use at 4:00 am in the morning with a bad case of insomnia :)

At any rate, I'll give it another 'go'..... and we'll see
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top