Using If to determine if form fields are blank (1 Viewer)

David Ball

Registered User.
Local time
Today, 16:20
Joined
Aug 9, 2010
Messages
230
Hi,

I have a form frmContacts where a person’s name and address etc can be entered.
There are comboboxes for Country, State and City (in that order).
I want the State and City comboboxes to be not visible until a value is selected from the Country combo.
I have done this using,
Forms!frmContacts.Combo2.Visible = False
Forms!frmContacts.Combo4.Visible = False
,on the forms On Open event.
I then show the combos, as required, by using Forms!frmContacts.Combo2.Visible = True on first the Country combo’s After Update event, and then similar on the State combo to show the City combo.
The problem is that this hides the combos for all records, including the ones where a value has already been selected for all of these combos. I need to display these for records that already exist and only have them hidden when I scroll to the end of the list and onto next (blank) record.
I need something like an IF to test if there are values already.
How would I modify,
Forms!frmContacts.Combo2.Visible = False
Forms!frmContacts.Combo4.Visible = False
,to do this?

Thanks very much

Dave
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 14:50
Joined
May 7, 2009
Messages
19,233
move your code to the Form's Current Event.

private sub Form_Current()
Me.Combo2.Visible = Trim(Me.CountryCombo & "")<>""
Me.Combo4.Visible = Trim(Me.CountryCombo & "")<>""
End Sub


also call this sub from CountryCombo AfterUpdate:


Private sub CountryCombo_AfterUpdate()
Call Form_Current
End Sub
 

CJ_London

Super Moderator
Staff member
Local time
Today, 07:50
Joined
Feb 19, 2013
Messages
16,607
when I scroll to the end of the list and onto next (blank) record
this implies you have a continuous form. If this is the case, then the visible property will affect all rows. Best you can do is to use conditional formatting to disable the controls. Or alternatively make the forecolor the same as the back color so the control is not obvious - but it will still be selectable
 

Micron

AWF VIP
Local time
Today, 02:50
Joined
Oct 20, 2018
Messages
3,478
You would have to change your form to a single record type. Then you could do something without affecting other instances of the same control. Aside from being able to see multiple unrelated records (i.e. each one is a different person) there's probably no requirement for a continuous form. Note that if you alter the choice in a bound combo box, you change the stored value. Thus they don't always make for good bound controls regardless of the form type.
 

theDBguy

I’m here to help
Staff member
Local time
Yesterday, 23:50
Joined
Oct 29, 2018
Messages
21,467
If this is on a continuous form, I am with CJ on using conditional formatting to disable the controls.

Just my 2 cents...
 

Users who are viewing this thread

Top Bottom