Change Caption Problem

kirkm

Registered User.
Local time
Tomorrow, 10:26
Joined
Oct 30, 2008
Messages
1,257
Not sure why this is giving so much trouble

Dim frm As Form
Set frm = Form_frmExtSingles
With frm
.RecordSource = sql
!xLabel.Caption = "Composer"
' Forms!Form_frmExtSingles!xLabel.Caption = "Composer"
.TheCaption = Cap1
.Sizer
.Visible = True
End With
Set frm = Nothing

I cannot apply a new caption for xLabel control. Am told either Form doesn't exist, or field doesn't exist.
Is this because the Form is dsplayed in datasheet mode ?
 
Maybe because you are instantiating the form's code module, rather than the form itself. Form modules don't have controls. Just a thought...
 
did you set the "Has Module" property to Yes?
 
I think the culprit is this line:

Code:
Set frm = Form_frmExtSingles

That isn't a form. Forms("Form_frmExtSingles") would be an instantiated form. Without more syntax than you presented, Form_frmExtSingles is merely an undeclared variable.
 
Form_frmExtSingles is merely an undeclared variable.
if "Has Module" is set:

Set frm = Form_frmExtSingles (is Valid)
Set frm = New Form_frmExtSingles (also Valid)
 
Thanks the replies but I'm mot quite up with what it all means. "Has Module" (which I'd never heard of) is Yes (must be the default).
Even after Googling I'm unsure what is meant by instantiated. My Form isn't a Form ??
Well, in the code block I have what instruction would change the Caption text ?
 
Thanks the replies but I'm mot quite up with what it all means. "Has Module" (which I'd never heard of) is Yes (must be the default).
Even after Googling I'm unsure what is meant by instantiated. My Form isn't a Form ??
Well, in the code block I have what instruction would change the Caption text ?
Hi. Basically, what you see listed in the Nav Pane as frmExtSingles is a Form object, and it contains Labels with Captions. What you in the VBE window as Form_frmExtSingles is a Class Module, and it doesn't contain any Labels with Captions.

Try changing your code to something like this and see if it works.
Code:
Set frm = CurrentProject.AllForms("frmExtSingles")
Hope that helps...

(Untested - Sent from phone...)
 
That line brings up
Run-time error '13':

Type mismatch.

Puzzling...
 
That line brings up
Run-time error '13':

Type mismatch.

Puzzling...
Sorry, I can't test it right now. I'm not in front of a computer, but I hope what I'm trying to say makes sense.

Sent from phone...
 
Not sure why this is giving so much trouble

Dim frm As Form
Set frm = Form_frmExtSingles

I cannot apply a new caption for xLabel control. Am told either Form doesn't exist, or field doesn't exist.
Is this because the Form is dsplayed in datasheet mode
As I have explained before, any reference to an unopened form by its module will open an instance in the Forms Collection that has no item name. AFAIK there is no way to refer to this instance, though I have not tried setting it to a variable as you have. (I will try that some time out of curiosity.)

One thing for sure you cannot refer to it like this.
Forms!Form_frmExtSingles!xLabel.Caption = "Composer"

Perhaps you can set some properties through the variable but I would not be surprised if some control properties on the itemless instance might be inaccessible.

The process should be to open the form, then set the properties of that form's item-named instance via the Forms Collection. You can open it with Visible false using one of the parameters in the OpenForm Method if you don't want the user to see the changes happen.

Some developers here disagree and continue to advise people to refer to the Form_formname, Follow their advice instead if you like and put up with the consequences. Read on from Post #11 in your recent thread. Isaac's said he would keep doing it for the Intellisense in Post #26. We clearly have a different idea of what is important.

 
There is a difference between changing a form's caption on the fly and changing it permanently. To change it permanently, don't use code. Just open the form and change the caption property. To change it on the fly, do it in the form' Load event. If the caption is dependent on something the calling form "knows", the calling form can load a value in a global as I did in this example.
Code:
Private Sub Form_Load()
    Me.Caption = gCodeDesc
End Sub
Or you can use a TempVar or the OpenArgs property.
The image below is from a mini-app that exists within most of my other apps that is used to manage lookup tables. when you choose a "table" from the code tables list, it opens another form and that form uses the name of the table as its caption.
ChangeCaption.JPG
 
Read on from Post #11 in your recent thread. Isaac's said he would keep doing it for the Intellisense in Post #26. We clearly have a different idea of what is important.
Context:

I actually humbled myself to request that you expound on it to explain why there are bad consequences to doing so, and you never replied to me.
1615929855504.png

After you didn't reply, I tried to "guess" what your reply might be by perusing through the remainder of the thread, but not finding a clear answer, I then posted what I did about continuing to use it.
 
I've lost the plot here completely. Who's talking to who? But Pat - it's not the Form caption I want to change, but a labels caption on the Form.
I'm not familiar with the concept of a Form Vs it's module. Isn't isn't all code in the Form? I can't fathom what "Form is not in the Forms collection" is supposed to convey. If I cannot change the labels caption, tell me it isn't possible and I'll leave it as it is.
 
I'm not familiar with the concept of a Form Vs it's module.
Did my explanation in Post #7 not help clarify that? Essentially, the Form has the Labels, the Module has the code - no Labels.
 
Did my explanation in Post #7 not help clarify that? Essentially, the Form has the Labels, the Module has the code - no Labels.
I think that confuses more than it clarifies. Because by using Form_Formname.controlname, you actually can (and I usually do) refer to the labels. And textboxes, and comboboxes, etc.
 
There's code for various controls and events, Yes ? I think of them as "code within the Form". I don't see a distinct "module" except as a different item in the LH Navigation column, or the Project Explorer, and I get the two confused sometimes. The code in msg #1 is not in a module but a Forms d-click event, and opens another Form. This opens on top of the first form. All this is very hard to explain. You'd think changing a labels caption would be a pretty simple thing to do, and it usually is.
 
I think that confuses more than it clarifies. Because by using Form_Formname.controlname, you actually can (and I usually do) refer to the labels. And textboxes, and comboboxes, etc.
I see, thanks. Can you explain why the OP got an error, then?
 
I see, thanks. Can you explain why the OP got an error, then?
The OP wasn't using the method I mentioned.

@kirkm
Just curious, does this work?
Code:
Form_frmExtSingles.xLabel.Caption = "Composer"
Obviously, I'm trusting that your form name is correct (frmExtSingles) and your control name is correct (xLabel)
 
There's code for various controls and events, Yes ? I think of them as "code within the Form". I don't see a distinct "module" except as a different item in the LH Navigation column, or the Project Explorer, and I get the two confused sometimes. The code in msg #1 is not in a module but a Forms d-click event, and opens another Form. This opens on top of the first form. All this is very hard to explain. You'd think changing a labels caption would be a pretty simple thing to do, and it usually is.
Hi. Also, there are, at least, two types of code modules in Access. There is a Standard module, and there is also a Class module. The form's module happens to be a type of Class module.
 
Isaac, you'd think that would but it gives a compile error highlighting .xlabel and saying Method or data member not found.
The Form name is correct. In design mode it shows 4 labels in the Form Header and 4 Text Boxes in the detail. The Form shows in datasheet mode. So I presume the column headers are those 4 labels. But am I wrong ? In the Property sheet the Name shows as "xLabel Label". That isn't my naming convention. So I tried
Code:
Form_frmExtSingles.[xLabel Label].Caption = "Composer"
That doesn't give an error but nor does it change the caption. I had tried "xLabel Label" to begin and when that didn't work, just "xlabel'
 

Users who are viewing this thread

Back
Top Bottom