Command Button to Enable Text box

RexesOperator

Registered User.
Local time
Yesterday, 19:01
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.
 
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
 
Or

Me.txtMAILINGADDRESSLINE1.Enabled = Not Me.txtMAILINGADDRESSLINE1.Enabled
 
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.
 
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.
 
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.
 
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!
 
Silly question, I know, but do you have your control correctly identified in your code?
 
Looks like you answered my question before I had posted it :eek: Sorry.

Try this page
 
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

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?
 
Something is goofed in there. I imported the objects into a new db and then added that code again, and it worked fine.
 
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: 149
  • FormPropertiesPg2.jpg
    FormPropertiesPg2.jpg
    42.8 KB · Views: 160
  • FormPropertiesPg3.jpg
    FormPropertiesPg3.jpg
    31.4 KB · Views: 140
Have you tried importing all the objects into a new, blank db as I mentioned?
 
Sorry - missed that.

That worked. Thank you.

Now the question is why?
 

Users who are viewing this thread

Back
Top Bottom