Changing Field Controls on a Form

Sean25

Registered User.
Local time
Yesterday, 21:21
Joined
Feb 16, 2004
Messages
25
Another really simple (but easily forgotten) scenario:

Opening a form with a control button on another form. That I have no problem with. However, I wish to change the attributes of the controld of the field(s) on that form. Here is the code:

Private Sub Button_Click()
On Error GoTo Err_Button_Click

Dim stDocName As String

stDocName = "FormName"

DoCmd.OpenForm stDocName, acNormal, acEdit
Form.FIELDNAME1.Enabled = True
Form.FIELDNAME1.ForeColor = 1232564
(or whatever)

Exit_Button_Click:
Exit Sub

Err_Button_Click:
MsgBox Err.Description
Resume Exit_Button_Click

End Sub

Could anyone please tell me what I'm obviously missing? Thanks in advance,

S.
 
Sean25 said:
Form.FIELDNAME1.Enabled = True
Form.FIELDNAME1.ForeColor = 1232564

Code:
    Forms("FIELDNAME1").Enabled = True
    Forms("FIELDNAME1").ForeColor = 1232564
 
Re: Re: Changing Field Controls on a Form

Mile-O-Phile said:


Code:
    Forms("FIELDNAME1").Enabled = True
    Forms("FIELDNAME1").ForeColor = 1232564
Don't you need the form name in there? :)

Forms(stDocName)("FIELDNAME1").Enabled=True
Forms(stDocName)("FIELDNAME1").ForeColor = 1232564
 
one other question...

thanks. Again, i knew it was something simple i was missing, but for some reason i just couldn;t see it, nor find it in Access help, or in the knowledge base. Likely was searching incorrectly, or something.

One othere question, And this is something I haven't done before so I don't even know if it's possible.

Can you with a button action on one form, change another form's Record Source when you want to open the second form, but PRIOR to the form actually appearing on the screen?

IE, say the record source of a form is a Table. You want someone to be able to open that table flat with one button, but with another you want them to be able to open it after using a query to load the Form's fields. Exactly as happens when you open a Form with a Record Source based on a query, not a Table.

Thanks again.

S.
 
Re: Re: Re: Changing Field Controls on a Form

dcx693 said:
Don't you need the form name in there? :)

What a splendid innovation you have proposed, dcx693. :rolleyes: :p
 
Re: Re: Re: Re: Changing Field Controls on a Form

Mile-O-Phile said:


What a splendid innovation you have proposed, dcx693. :rolleyes: :p
I try to be helpful. :cool:
 
Okay, am I missing something?

Actually, neither works. :(

When I try the first suggestion, I get an "Object Doesn't Support this property or Method"

Again, the code snippet is as follows:

stDocName = "Form Name"

DoCmd.OpenForm stDocName, acNormal, acEdit
Form("FieldName").Enabled = True
Form("FieldName").Locked = False

The Form opens. Both attributes listed above are defaulted to the opposite settings (Enabled is No, Locked is Yes)

If I try the second option, I get the error message "Microsoft Access can't Find the field "FormName" referred to in your expression.

So, the first option seems "more" correct, however, why is the text field object not supporting the Enabled/Locked Method change?

S.
 
If I try the second option, I get the error message "Microsoft Access can't Find the field "FormName" referred to in your expression.
Your code here:
stDocName = "Form Name"
DoCmd.OpenForm stDocName, acNormal, acEdit

is telling Access to open a form called "Form Name". If your form is not actually called "Form Name" then you need to change it to the name of your actual form.
 
okay, honestly, I'm not that dim.

in my code I substitued the actual form name and field name with Form Name and Field Name in my post. I know better. It was looking for an object on the already open Form with the same name as the Form, which obviously doesn't exist.

S.
 
So using this statement:
Forms(stDocName)("FIELDNAME1").Enabled=True
where you substitute your actual form name in there and your actual field name produces "Microsoft Access can't Find the field FormName referred to in your expression." ?

Not to imply that you are dim, but I am simply trying to go over reasons why it might be failing.

When you substitute your actual form and field names, do you change this line:
stDocName = "Form Name"
to reflect the actual form name?

And then do you change:
Forms(stDocName)("FIELDNAME1").Enabled=True
by typing in the new field name?

I asking these very basic questions because the syntax of the statement is very important. If you pass a string variable, then you do not enclose it in quotes. If you pass a literal string, then you must enclose it in quotes.

If that is not the issue, then I'd urge you again to check your form and control names again to make sure you've got them correct.
 
Okay, once again, complete (with proper object names included) sub code for this button click action:

Private Sub AddCustomer_Click()
On Error GoTo Err_AddCustomer_Click


Dim stDocName As String

stDocName = "Add_Lookup_Edit"

DoCmd.OpenForm stDocName, acNormal, acEdit
Form(stDocName)("StoreName").Enabled = True
Form(stDocName)("StoreName").Locked = False

Exit_AddCustomer_Click:
Exit Sub

Err_AddCustomer_Click:
MsgBox Err.Description
Resume Exit_AddCustomer_Click

End Sub

When (stDocName) is included, the form appears on screen along with the following error message: Microsoft Access can't find the field 'Add_Lookup_Edit' referred to in your expression.

When the exact same code as above minus ONLY the two references to (stDocName) after Form, is used, the Form opens along with the following error message: Object doesn't support this property or method.

Thanks again,

S.
 
This is often the reason we ask the most basic questions... :)

Look at the line of code that I posted, which was:
Forms(stDocName)("FIELDNAME1").Enabled=True

Now look back at the code you posted.

Notice any differences, besides the control name being changed?
 
okay, I AM dim! :D

Thanks, that did it... now, any idea on my other problem (regarding changing the Record Source)? Or should that be re-posted to a new thread?

Thanks *once again*

S.
 
No problem!

You should probably post the other problem to a different thread since it's not really related. Good luck.
 

Users who are viewing this thread

Back
Top Bottom