Form VBA w/A2013 (1 Viewer)

I use the method when I pass variables via custom properties of a form. Strangely the forms "on load" and "on open" Events happened before the custom properties are set which is very annoying.
What do you mean by custom properties Uncle G?
 
It's good that you're learning VBA.

Forms is a collection of loaded forms in your db. A loaded form is one that is open in any view, i.e. design, single form, continuous form etc. When you enter the name of a form in Forms() you are referring to that particular form; regardless of which form the code is being run. The same thing goes for Controls(); it's a collection of controls in the form.

Now in your case, strFormName is a variable that holds the name of the menu form that you're opening, so in order to reference the label in the menu form we first refer to the form (i.e. Forms(strFormName)), followed by a dot, and then the name of the label (i.e. Controls("Name of label")). If you put all that together you get the code above.

I hope it makes sense.

I am starting to get it. does both forms have to be open (loaded)?
 
It's good that you're learning VBA.

Forms is a collection of loaded forms in your db. A loaded form is one that is open in any view, i.e. design, single form, continuous form etc. When you enter the name of a form in Forms() you are referring to that particular form; regardless of which form the code is being run. The same thing goes for Controls(); it's a collection of controls in the form.

Now in your case, strFormName is a variable that holds the name of the menu form that you're opening, so in order to reference the label in the menu form we first refer to the form (i.e. Forms(strFormName)), followed by a dot, and then the name of the label (i.e. Controls("Name of label")). If you put all that together you get the code above.

I hope it makes sense.
I was starting to get it but then I noticed you mention [label in menu form] The label is in the main data form. The string I put in the fx [.fX ("Supporting Churches")] is what needs to show up in the lbl on the main form. Please lay it on me again with that thought in mind
 
Yes you were getting it, that was supposed to say "Main form".

If you want to drive a car, you have to get in the car to drive it right? Then once you're in the car, you can change gears, change the direction of the steering wheel etc. Now the form is your car, in order to change the property of one the controls in the car, you need to first access that form. That's why you do this Forms(strFormName) to access the form, followed by a dot, then to access the controls, i.e. textbox; label etc, you write Controls("Label Name") afterwards.

You set the caption after opening the form.
 
Yes you were getting it, that was supposed to say "Main form".

If you want to drive a car, you have to get in the car to drive it right? Then once you're in the car, you can change gears, change the direction of the steering wheel etc. Now the form is your car, in order to change the property of one the controls in the car, you need to first access that form. That's why you do this Forms(strFormName) to access the form, followed by a dot, then to access the controls, i.e. textbox; label etc, you write Controls("Label Name") afterwards.

You set the caption after opening the form.

Thanks, think I got it. Oh! in case I crash, where's the brake pedal:D
 
VB

What am I missing? Opens but doesn't change label.
Code:
  '------------------------------------------------------------
  ' TRYING SHORT VBA
  ' cmdSupportingCh_Click via Dick's Main menu
  'opens church form filtered with just supporting churches
  '------------------------------------------------------------
  Private Sub cmdSupportingCh_Click()                                  
  Dim strFrmName As String
  strFrmName = "frmChurchesAllDick"                                
     DoCmd.OpenForm strFrmName
     DoCmd.ApplyFilter "qrySupportingCh"
    Forms(strFrmName).Controls("lblSupportingCH").Caption = "Supporting Churches"                              '  DoCmd.Close acForm, "frmMainMenuDick", acformyes
  End sub
 
Check that the Visible property of the label is set to True.
 
Check that the Visible property of the label is set to True.

Funny you should say that, as I am working on a copy. It did have the visible property as no. I found that right away. I thought sure that is what is was going to be, but it wasn't.
 
So after setting it back to Yes you're back up and running?
 
So after setting it back to Yes you're back up and running?

No, I reset to yes before you suggested it. It opens but doesn't change the label. It show the generic name that I have in there.
 
Something isn't right. Can you upload a db with just the two forms attached Dick7?
 
I can't see any of the code suggested in the db. Can you upload something with your trials that isn't working.

By the way, how do you manage to read those command buttons with the pale yellow fore colour? :)
 
I can't see any of the code suggested in the db. Can you upload something with your trials that isn't working.

By the way, how do you manage to read those command buttons with the pale yellow fore colour? :)
Actually they are dark green. They came out that way when I zipped them.
I not sure what you are asking me to send.
 
Strange!

Don't worry, I found the bit of code you said wasn't working.
I just tested it and in fact it is changing the caption to "Supporting Churches".
 
Thanks for your help
It is working!
I hate it when I do dumb things. On the other copy I had switch the embedded text from supporting churches to generic. when I made a copy from an earlier version I forget to switch it back, so supporting churches was already the text.

If you still have that menu form it has a cmd for states. Is it possible to pick up the 2 letter abbreviation of whatever state (FL, MS etcs.) I query in the dialog box and put it in the label?

Ps. if you ever come to FL (when I am home, I am in MS right now) I will treat you to the best Chines Buffet in the whole US and TX.
 
Yeah, I noticed that you had saved "Supporting churches" as the default caption and guessed that may have been the confusion.

If you still have that menu form it has a cmd for states. Is it possible to pick up the 2 letter abbreviation of whatever state (FL, MS etcs.) I query in the dialog box and put it in the label?
You mean the dialog box is a parameter in your query?

Ps. if you ever come to FL (when I am home, I am in MS right now) I will treat you to the best Chines Buffet in the whole US and TX.
That's kind of you. I was in the LA and Vegas last year... might be going to NY later this year.
Can the Chinese buffet be as good as what we get here in the London? ;)
 
Yeah, I noticed that you had saved "Supporting
Don't know as I have never eaten @ a Chinese Buffet in London, but I have eaten in Chinese Buffets in 33 states in US. In fact I can't even remember much of what I ate in UK. Of course I was only 19, so all I remember that a young woman took me drinking and she ordered us a pims #1 or 2. Or something like that.

You mean the dialog box is a parameter in your query?
Yes, sometimes I look for churches by state. In fact I just had to send a associate a list of all the churches I had for AZ. So is it possible to have my label show what state I enter in?


BTY:
I have ask this before, but nobody seems to know what happened to John Big booty. He invites me to Aussie country.
 

Users who are viewing this thread

Back
Top Bottom