How To: use one control to enable or activate another control?

245

New member
Local time
Today, 02:17
Joined
Jul 25, 2010
Messages
8
I have attached an image of the physical form

How do I use one (1) control to enable/activate another control? EXAMPLE: on a form --to use a checkbox, once checked, to enable a grayed-out field or combobox. Once said field/combobox is enabled/activated via the checkbox the choice can be selected from the combobox or typed in to the field, thereafter entered in to the databases' table(s) and/or printed on to the form I've provided herein and described below.

This is a bit of a project for me, the title/subject of this thread/discussion is only the begining.

THE GOAL: I have NCR (carbonless) forms (4-pages) see attached image/file. The data that normally (manually) gets entered into these forms, --I plan to employ Access for the task by entering all the data into Access; thereafter have the data ;pulled (queried) from Access and printed via a line printer. This appears easier said than done.

My current speed bump(s) are:
The form has various items that have a check box associated with each item. I need to be able to, via the printer, check any number of these check boxes, perhaps all of them --on the physical form--, while making the data entry in the correct field(s) within access.

example -- on the physical form we have:
heading = service type
rush x next flight x
over night x priority x

The 'x' marks a placeholder for the checkbox on the physical form --see attached image/file--

Currently, on the draft 'access form' I've created a combobox with the above listings in addition to the default listing of 'none' or 'no'. I am at a complete loss of 'how to:', after making a selection from the combobox, instead of just entering data into a table\field; what should I be reading/doing in order to both, make the entry in to the accessDB and place an 'x' in the proper checkbox on the physical form via the printer?

Assuming the database\field(s) are holding a positive value how would I tell the printer to find/associate, possibly multiple fields, with the correct listing(s) on the physical form and place an 'x' in the associated checkbox?

I hope I was clear/detailed enough without being long winded. If needed I will provide the draft 'unpopulated' database.

NOTE-1: I have attached an image of the physical form.
NOTE-2: I have not acquired the printer as yet. I needed to be sure access is able to handle what I am describing herein; these line printers are not a joke when it comes to purchasing.
 

Attachments

Firstly Welcome to the forum.

You can use the following in the On Click event of you check box to enable another control;
Code:
If Me.CheckBoxName = -1 Then
     Me.ControlName.Enabled = True
Else
     Me.ControlName = Null  [COLOR="SeaGreen"] 'Set Control to default value if Check Box is unchecked[/COLOR]
     Me.ControlName.Enabled = False
End IF


You would also need also need the following code in the Form's On Current event;
Code:
If Me.CheckBoxName = -1 Then
     Me.ControlName.Enabled = True
Else
     Me.ControlName.Enabled = False
End IF
 
If you want a very simple code you could reduce the code for the On Current Event to;
Code:
Me.ControlName.Enabled = Me.CheckBoxName
This will work as the Enabled argument is looking for a True or False value which the Check box returns, as True = -1 and False = 0
 
Firstly Welcome to the forum.

You can use the following in the On Click event of you check box to enable another control;
Code:
If Me.CheckBoxName = -1 Then
     Me.ControlName.Enabled = True
Else
     Me.ControlName = Null  [COLOR="SeaGreen"] 'Set Control to default value if Check Box is unchecked[/COLOR]
     Me.ControlName.Enabled = False
End IF


You would also need also need the following code in the Form's On Current event;
Code:
If Me.CheckBoxName = -1 Then
     Me.ControlName.Enabled = True
Else
     Me.ControlName.Enabled = False
End IF
Thanks for both the 'Welcome" and the reply.

I did forget to mention I'm using the OFFICE 2007. 'Check50' is the enabled checkbox and 'Check52' is the disabled checkbox... I fear I have done something incorrectly; Here's what I understood you to say:


Private Sub Check50_Click()
If Me.Check50 = -1 Then
Me.Check52.Enabled = True
Else
Me.Check52 = Null
Me.Check52.Enabled = False
End If

End Sub


Private Sub Form_Current()
If Me.Check50 = -1 Then
Me.Check52.Enabled = True
Else
Me.Check52.Enabled = False
End If

The above code results in the following error:

Microsoft Office Access can't find the object 'if Me.' <-- should it not be looking for either 'Check50' or 'Check62'? I find it most interesting that all of the code you provided is needed to do something that appears to be so simple, but, I'm all ears. :~)
 
Any chance you can post a copy of your DB? The code looks fine, so I've no idea what's (not) going on :confused:
 
OK; I see what the problem is, you have tried to put the code into event tab. What you need to do is select [Event Procedure] from the drop down list, then click on the little button with the three full stops (Ellipsis) on it, this will open up you VBA code window, this is were the code I provided earlier belongs. Fix that and the code works as expected.
 
OK; I see what the problem is, you have tried to put the code into event tab. What you need to do is select [Event Procedure] from the drop down list, then click on the little button with the three full stops (Ellipsis) on it, this will open up you VBA code window, this is were the code I provided earlier belongs. Fix that and the code works as expected.

Hello-o Mr. Booty, I did exactly as you said. In fact, when I follow your directions again, as can be seen in the above quotes, here is what I'm presented with in the window that opens:

Option Compare Database

Private Sub Check4_Click()

End Sub

Private Sub SERVICE_TYPE_BeforeUpdate(Cancel As Integer)

End Sub

Private Sub Check50_Click()
If Me.Check50 = -1 Then
Me.Check52.Enabled = True
Else
Me.Check52 = Null
Me.Check52.Enabled = False
End If

End Sub

Private Sub Check52_Click()

End Sub

Private Sub Form_Current()
If Me.Check50 = -1 Then
Me.Check52.Enabled = True
Else
Me.Check52.Enabled = False
End If

End Sub

Your turn .... :-)
 
Its not working. check50, when checked/unchecked (using your script/code), continues to 'not' enabling/disabling the check52 checkbox/control.
And have you enabled your code by setting the database's location as a trusted location? Code (in 2007/2010) won't run unless you have either done that or clicked the enable button on the area below the ribbon when you first open the database.
 
And have you enabled your code by setting the database's location as a trusted location? Code (in 2007/2010) won't run unless you have either done that or clicked the enable button on the area below the ribbon when you first open the database.

1) Please accept my undiluted 'Thank you' to both SOS and Mr. Booty not only for your code but also your patients. Macros were in fact disabled as 'SOS' stated. Mr. Bootys' code is working.

2) Is there not a less coded way of doing this, when I say 'less coded' I mean, isn't there a native way within access to accomplish this without a user having to learn how to code/script?

3) Without giving me 'Access or VBA' hand held lessons, keeping in mind the help files and/pages can most times be long winded with vague example (to a new user); do I really 'need' to learn VBA for use with access\forms\subforms?


4) If learning VBA is somewhat a prerequisit; other than taking a class, where should I start --other than the begining or reading through someone elses code in order to find out what the code is doing. --coping someone elses code isn't always the way to go.

I've tried coding and scripting in the past. I always find myself getting distracted by life and forgetting what I learned in the coding | scripting or computer community. Once I get this database up and running I'll need to know how to maintain it and any code it employs. When thigs break in the middle of the night ~ ~ ~

Please advise.
 
Last edited:
1) Please accept my undiluted 'Thank you' to both SOS and Mr. Booty not only for your code but also your patients. Macros were in fact disabled as 'SOS' stated. Mr. Bootys' code is working.

...........
Glad you got it sorted :)

......

2) Is there not a less coded way of doing this, when I say 'less coded' I mean, isn't there a native way within access to accomplish this without a user having to learn how to code/script?

.........

You can do a lot with macros, but I'm not sure if what we've just done was within the scope of a macro, I always go straight to VBA.

.....

3) Without giving me 'Access or VBA' hand held lessons, keeping in mind the help files and/pages can most times be long winded with vague example (to a new user); do I really 'need' to learn VBA for use with access\forms\subforms?


.......
I believe that you can do quite a bit using only macros. One approach is to create macros and then convert them to VBA and use that as a starting point for learning what various VBA commands and syntax look like.

There are a number of sites on the internet that offer tutorials and sample solutions;
These are all sites I have bookmarked (amongst many) that I refer to from time to time.
 

Users who are viewing this thread

Back
Top Bottom