Link to home
Start Free TrialLog in
Avatar of woodje
woodjeFlag for United States of America

asked on

Enable command button in subform after update event on main form.

I have a main form f_gu_gdr_entry that has a phone number text box. When you enter a phone number and tab out or press enter an after update event is fired and the form populates. I am trying to have a command button (cmd_f_gu_gdr_entry_country_sub_add) on a subform of (f_gu_gdr_entry_country_sub) become visible and enabled. Right now when I run the search no error is returned however the button remains not visible and not enabled. I have listed the code below. Any help you can give me would be great. Thanks.

Jeff
DoCmd.ApplyFilter "", "[Forms]![f_gu_gdr_entry]![txtmdnsearch]=[tblglobaldataroaming]![mdn]"
Forms!f_gu_gdr_entry!txtmdn = Forms!f_gu_gdr_entry!txtmdnsearch
DoCmd.GoToControl "txtregion"
 
Forms!f_gu_gdr_entry.f_gu_gdr_entry_usage_sub.Requery
 
If user.AccessID = 1 Or user.AccessID = 3 Or user.AccessID = 7 Or user.AccessID = 13 Then
Forms!f_gu_entry.f_gu_gdr_entry_country_sub.Form.cmd_f_gu_gdr_entry_country_sub_add.Visible = True
Forms!f_gu_entry.f_gu_gdr_entry_country_sub.Form.cmd_f_gu_gdr_entry_country_sub_add.Enable = True
End If

Open in new window

Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

if you are calling the codes in the main form

use

Me.f_gu_entry.f_gu_gdr_entry_country_sub.Form.cmd_f_gu_gdr_entry_country_sub_add.Visible = True
Me.f_gu_entry.f_gu_gdr_entry_country_sub.Form.cmd_f_gu_gdr_entry_country_sub_add.Enable = True
woodje,
your naming of forms and controls  are too long
oops, it is hard to read the codes

use

Me.f_gu_gdr_entry_country_sub.Form.cmd_f_gu_gdr_entry_country_sub_add.Visible = True
Me.f_gu_gdr_entry_country_sub.Form.cmd_f_gu_gdr_entry_country_sub_add.Enable = True
I agree with Cap: Your object names are way too long and convoluted to have any real meaning.

Note also that you must reference the Subform CONTROL that is being used on the main form. This may or may not be named the same as the form you're using as a Subform, but you must refer to it correctly:

Me.NameOfYourSubformCONTROL.Form.YourCommand.Visible = True

Avatar of woodje

ASKER

Cap,

Thanks for the info. The command button is now visible however I am getting a Run-time error '438':
Object doesn't support this property or method

This is occuring on the line:
Me.f_gu_gdr_entry_country_sub.Form.cmd_f_gu_gdr_entry_country_sub_add.Enable = True

I labeled the forms with this structure.
f = form
gu= global usage
gdr = global data roaming
entry = is the entry form
country = is the type of subform
sub = subform.

Then the control is as follows
cmd = command button
then the same for all till you get to country sub form.  


Me.f_gu_gdr_entry_country_sub.Form.cmd_f_gu_gdr_entry_country_sub_add.Visible = True

Me.f_gu_gdr_entry_country_sub.Form.setfocus   'Add this line


Me.f_gu_gdr_entry_country_sub.Form.cmd_f_gu_gdr_entry_country_sub_add.Enable = True


or if you have any other control , textbox or command button

set the focus to either one of them before enabling

cmd_f_gu_gdr_entry_country_sub_add




Is "f_gu_gdr_entry_country_sub" the name of your Subform CONTROL, or is it the name of the Form that you're using as a Subform? They may be the same, but in many cases they are not ... the error you're getting is strongly indicative of improper syntax.

In the image below, the Subform CONTROL that I'm using is named "sfManagers" ... however, the Form that is being used as a subform in named "frmManagers". In this case, I'd refer to it as such:

Me.sfManagers.Form.SomeControl

If I instead refer to it as:

Me.frmManagers.Form.SomeControl

Access will throw an error, since there is no control named "frmManagers" on my form.
SubformControl.jpg
Avatar of woodje

ASKER

Cap,

I added your first example and get the same results. And when I setfocus to a combo box in the subform then try and enable the button I get the same thing.

LSM,

My subform control name and the form that makes the subform are the same name. I have checked the spelling of both the control name and the subform several times. Thanks for the suggestions.
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of woodje

ASKER

Cap,

That did it. LOL One little letter causes that much pain.