Command Button to Enable Text box (1 Viewer)

RexesOperator

Registered User.
Local time
Today, 15:28
Joined
Jul 15, 2006
Messages
604
I am getting too sleepy to concentrate on this. I have been wandering around here and on Google for awhile.

I have a main form frmCompaniesMain and sub form frmContactsSub

On the subform there are several text boxes disabled. They only need to be enabled when the command button cmdMailingAddress is clicked.

ATM I have:

Private Sub cmdMailingAddress_Click()

if Me.txtMAILINGADDRESSLINE1.Enabled = false
then Me.txtMAILINGADDRESSLINE1.Enabled = true

End Sub

Nothing happens.
 

Luddite Lad

Registered User.
Local time
Tomorrow, 05:28
Joined
Aug 23, 2005
Messages
177
Try

Code:
Private Sub cmdMailingAddress_Click()

If Me.txtMAILINGADDRESSLINE1.Enabled = false Then
      Me.txtMAILINGADDRESSLINE1.Enabled = true
Else
      Me.txtMAILINGADDRESSLINE1.Enabled = false
End If

End Sub
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 12:28
Joined
Aug 30, 2003
Messages
36,139
Or

Me.txtMAILINGADDRESSLINE1.Enabled = Not Me.txtMAILINGADDRESSLINE1.Enabled
 

RexesOperator

Registered User.
Local time
Today, 15:28
Joined
Jul 15, 2006
Messages
604
Neither worked.

One question - does vba require an else to an if then statement? As in Luddite Lad's example? I know Pascal (the programming language - not the mathmatician) didn't.
 

Luddite Lad

Registered User.
Local time
Tomorrow, 05:28
Joined
Aug 23, 2005
Messages
177
Not sure why the code doesn't work, as I've just cut and pasted it straight back into a test form, and it works fine :confused:

An If Then statement doesn't need an else statement, but in this case it does otherwise the control will remain disabled after the first click, unless there is another operation to reset it to enabled. I had just assume that you wish to toggle between disabled and enabled with a single button.
 

Luddite Lad

Registered User.
Local time
Tomorrow, 05:28
Joined
Aug 23, 2005
Messages
177
Just tested Paul's code as well and it works fine too. I'd use Paul's code as it is far simpler than mine.
 

RexesOperator

Registered User.
Local time
Today, 15:28
Joined
Jul 15, 2006
Messages
604
I think the issue is the command button and text boxes are on a subform. I will check that syntax in the morning.

Enjoy the holiday!
 

Luddite Lad

Registered User.
Local time
Tomorrow, 05:28
Joined
Aug 23, 2005
Messages
177
Silly question, I know, but do you have your control correctly identified in your code?
 

Luddite Lad

Registered User.
Local time
Tomorrow, 05:28
Joined
Aug 23, 2005
Messages
177
Looks like you answered my question before I had posted it :eek: Sorry.

Try this page
 

RexesOperator

Registered User.
Local time
Today, 15:28
Joined
Jul 15, 2006
Messages
604
Looks like you answered my question before I had posted it :eek: Sorry.

Try this page


Thanks for the reference. I've seen it before - I just couldn't remember where. Your code works fine on a blank database, but just not mine.

I have attached a copy to see if you can see where the problem is.
 

Attachments

  • Copy (2) of ZTrial.zip
    86.8 KB · Views: 123

RexesOperator

Registered User.
Local time
Today, 15:28
Joined
Jul 15, 2006
Messages
604
I tried Paul's code as well. I couldn't get it to work on a blank form. But I would still like to get the control working on this form. Any ideas about why it won't work?
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 12:28
Joined
Aug 30, 2003
Messages
36,139
Something is goofed in there. I imported the objects into a new db and then added that code again, and it worked fine.
 

RexesOperator

Registered User.
Local time
Today, 15:28
Joined
Jul 15, 2006
Messages
604
I know. In the same db I got the code to work on a blank form.

Some of the other things I have done is create a blank form and copy and paste the text boxes etc. Same problem - it doesn't work. I have also tried different ways of referencing the text box as per Luddite Lad's reference page.

I have attached screen shots of the form properties in case you can see something.

I should add this is Access2003.
 

Attachments

  • FormPropertiesPg1.jpg
    FormPropertiesPg1.jpg
    56.6 KB · Views: 120
  • FormPropertiesPg2.jpg
    FormPropertiesPg2.jpg
    42.8 KB · Views: 131
  • FormPropertiesPg3.jpg
    FormPropertiesPg3.jpg
    31.4 KB · Views: 114

pbaldy

Wino Moderator
Staff member
Local time
Today, 12:28
Joined
Aug 30, 2003
Messages
36,139
Have you tried importing all the objects into a new, blank db as I mentioned?
 

RexesOperator

Registered User.
Local time
Today, 15:28
Joined
Jul 15, 2006
Messages
604
Sorry - missed that.

That worked. Thank you.

Now the question is why?
 

Users who are viewing this thread

Top Bottom