Disabling subform until combo box is populated?

NewShoes

Registered User.
Local time
Today, 11:58
Joined
Aug 1, 2009
Messages
223
Hi All,

As the title says really...I have a form with a combo box and a subform. When the user opens the form I'd like to prevent them from entering a record in the subform before they select an option from the combo box.

The combo box is linked to the subform via child/master links as normal.

Thanks,
-NS
 
Code:
Private Sub ComboBoxName_AfterUpdate()
 If IsNull(Me.ComboboxName) Then
  Me.SubformControlName.Locked = True
 Else
  Me.SubformControlName.Locked = False
 End If
End Sub

Private Sub Form_Current()
 If IsNull(Me.ComboboxName) Then
  Me.SubformControlName.Locked = True
 Else
  Me.SubformControlName.Locked = False
 End If
End Sub
Linq ;0)>
 
In this case I might even programmatically load and unload the subform as needed.

Code:
sub form_current()
  LoadUnloadSubform
end sub

sub combo1_click()
  LoadUnloadSubform
end sub

sub LoadUnloadSubform
[COLOR="Green"]  'always unloads[/COLOR]
  me.subform1.sourceobject = ""
[COLOR="Green"]  'conditionally reloads[/COLOR]
  if HasValidData(me.combo1) Then me.subform1.sourceobject = "NameOfSubform"
end sub
Not shown is the HasValidData() routine to determine if data in the combo is OK.
Cheers,
 
I like linq's approach too, but I would condense this...
Code:
 If IsNull(Me.ComboboxName) Then
  Me.SubformControlName.Locked = True
 Else
  Me.SubformControlName.Locked = False
 End If
... to this ...
Code:
  Me.SubformControlName.Locked = IsNull(Me.ComboboxName)
...but that's a bit of a style thing too. They both work.
Cheers,
 
I've never been a fan of that kind of thing, especially when answering newbies, as I think it makes it less than obvious exactly what is being done...but of course it works! :D

In the early days of programming, when memory was a precious commodity, we actually held competitions to see who could perform a given task with the least number of keystrokes! But that's a rather moot point, today. Also, with so many non-hardcore coders and newbies out there, tackling development and modification of old programs, code clarity is of the essence.

Linq ;0)>
 
This is super old but I'm need of help.It's not recognizing my subform and my comboboxes when i type these in. I do not know what I'm doing wrong but my combobox is on a navigation form (main form) and my subform is a query driven datasheet subform.

Issue#1.PNG

I don't know if they are truly subforms (all my forms i created for navigation form would in my mind be a main form) Please help!
 

Users who are viewing this thread

Back
Top Bottom