Text value changed by OnClick event of Command Button

RexesOperator

Registered User.
Local time
Today, 09:53
Joined
Jul 15, 2006
Messages
604
I am using Access 2003.

I have a command button on a sub form that I want to use to change the value of a text box.

The main form is frmAddCompanies.
The sub form is frmAddCompaniesSub.
The command button I am using is cmdADDNewContactMailing.
The text box I want to change is txtMAILINGSAMEASCOMPANY. The data type is text. The default value is Y. I want the value to change to N when the command button is clicked.

I know the form and control references are correct because I use them in the same procedure to enable and disable other text boxes. I have also tried no quotes and single quotes.

This dosen't work, but I don't know why.

Private Sub cmdADDNewContactMailingAddress_Click()

If Forms!frmAddCompanies.frmAddCompaniesSub.Form.txtMAILINGSAMEASCOMPANY.Value = "Y" Then
Forms!frmAddCompanies.frmAddCompaniesSub.Form.txtMAILINGASAMEASCOMPANY.Value = "N"
Else
Forms!frmAddCompanies.frmAddCompaniesSub.Form.txtMAILINGASAMEASCOMPANY.Value = "Y"
End If

End Sub
 
There'snothing wrong with the Value! It's not necessary, as it's the default property, but it's not hurting anything.

To begin with, your code isn't just setting the value to "N." It sets it to "N" only if it is already set to "Y." If It is currently set to "N" it sets it to "Y."

Also, in all of your code, you identify your textbox as

Forms!frmAddCompanies.frmAddCompaniesSub.Form.txtM AILINGSAMEASCOMPANY

with a space between the M and AILINGSAMEASCOMPANY.

Is this a typo in your post, or is this how it actually is in the code? Shouldn't it be

MAILINGSAMEASCOMPANY with no space?
 
The spacing is one of those forum things. It is correctly spelled in the procedure.

And yes the default value is set to Y. I just want to change it to N when there is a need for a different mailing address.

I get an error message : Run-time error '2465' Application-defined or object-defined error. The debug stops on the else statement.
 
From Access Help

TextBox.Value Property
Determines or specifies the text in the text box. Read/write Variant.
Syntax
expression.Value
expression A variable that represents a TextBox object.

Remarks
The Text property returns the formatted string. The Text property may be different than the Value property for a text box control. The Text property is the current contents of the control. The Value property is the saved value of the text box control. The Text property is always current while the control has the focus.
The Value property returns or sets a control's default property, which is the property that is assumed when you don't explicitly specify a property name.


Get rid of the .value

For recordsource data, the .value is the default, for textbox, it refers too the property, not the contents.
 
With Error 2465 Access is telling you that it can't find one of the objects you're referencing, so I guess you need to check all of the names in your code.
 
I dropped the .value and stepped through the procedure again. Same error. Then I used copy and paste to make sure the references were correct. A typo of some sort must have crept in.

The greatest gifts to programmers from Microsoft? Copy/paste and undo.

Thank you Access gods and goddesses!
 

Users who are viewing this thread

Back
Top Bottom