Form Wizard to add CHECK box (1 Viewer)

liddlem

Registered User.
Local time
Today, 11:26
Joined
May 16, 2003
Messages
339
Hi All
My DB has MANY bit fields.
Whenever I use the form wizard to create a form, it creates a text box for each field. Is there a preferences setting (or script) that I can use to change all the text boxes (for bit fields) to CHECK boxes.
Thanks
 

liddlem

Registered User.
Local time
Today, 11:26
Joined
May 16, 2003
Messages
339
Unfortunately the 'right click' does not offer me the 'checkbox' option. (Checkbox, Toggle and Option buttons are all grayed out.)
I first have to delete the textbox first and then insert a checkbox. Then bind the checkbox to the data.
This is a pain in the proverbial!
 

sneuberg

AWF VIP
Local time
Today, 03:26
Joined
Oct 17, 2014
Messages
3,506
I tried to replicate your problem but when I tried it the controls the Access wizard added were checkboxes but then my table has Yes/No field. What's a bit fields? Is that something from a linked table?

Someone could probably write a script to do this conversion but that's a lot of work. It's too bad arnelgp disappeared. That's just the kind of thing he would be willing to do.
 

sneuberg

AWF VIP
Local time
Today, 03:26
Joined
Oct 17, 2014
Messages
3,506
No promises but I've started working on a script. If all it needs to do is create a checkbox with the same position (left and top) and control source maybe it's not as much work as I thought. If it gives it the same name it will have to rename the text box to something else. If you describe what you've been doing manually I'll try to included those steps it in.

I might be able to get you something tomorrow.
 

liddlem

Registered User.
Local time
Today, 11:26
Joined
May 16, 2003
Messages
339
Wow - that would be much appreciated. The same co-ords as the existing box would be fine. I am already having to relocate the fields anyhow.
 

JHB

Have been here a while
Local time
Today, 12:26
Joined
Jun 17, 2012
Messages
7,732
Couldn't you create a query which create a local table and use the local table in connection with the wizard.
And ofcause afterwards delete the local table and query.
 

liddlem

Registered User.
Local time
Today, 11:26
Joined
May 16, 2003
Messages
339
Good Thinking 007. . .
I Have Many Such Tables (with The Scripts That Created Them)
So Your Idea Might Just Work Wonders.
I Shall Give It A Go.
 

sneuberg

AWF VIP
Local time
Today, 03:26
Joined
Oct 17, 2014
Messages
3,506
JHB's suggestion will probably work but I went ahead and creating an application to do the conversion anyway. Probably some sort of avoidance behavior on my part. The database is attached.

Everything is done in the TextboxConverter form so if you want to use this all you need to do is import that form into your application. I left a table and some forms (Form1 and Form2) in the attached database so that you could test it.

Most of the code in this is just to select the textboxes. The meat in this is the ConvertTextBoxToCheckbox subroutine and is as follows:

Code:
Dim ControlName As String
Dim ctlCheckBox As Control

If ControlExists(ctrl.Name & "_Old", frmName) Then
    Exit Sub
End If
ControlName = ctrl.Name
ctrl.Name = ctrl.Name & "_Old"
Set ctlCheckBox = CreateControl(frmName, acCheckBox, acDetail, , ctrl.ControlSource, ctrl.Left, ctrl.Top)
ctlCheckBox.Name = ControlName
If Me.DeleteTextBoxes Then
    DeleteControl frmName, ctrl.Name
End If

Where

Code:
If ControlExists(ctrl.Name & "_Old", frmName) Then
    Exit Sub
End If

is just to make sure the control isn't converted twice.

Code:
ControlName = ctrl.Name
ctrl.Name = ctrl.Name & "_Old"

Saves the textbox name and renames it.

Code:
Set ctlCheckBox = CreateControl(frmName, acCheckBox, acDetail, , ctrl.ControlSource, ctrl.Left, ctrl.Top)
ctlCheckBox.Name = ControlName

creates the checkbox with the properties of the textbox and give it the name of the textbox.
Code:
If Me.DeleteTextBoxes Then
    DeleteControl frmName, ctrl.Name
End If

deletes the textbox if that option is selected in the form.
 

Attachments

  • ConvertControl.accdb
    452 KB · Views: 42

liddlem

Registered User.
Local time
Today, 11:26
Joined
May 16, 2003
Messages
339
Sir - You are an officer and a gentleman.
I thank you
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 20:26
Joined
Jan 20, 2009
Messages
12,853
BTW Access has certain requirements when linked to bit columns in SQL Server.

You must disallow Nulls and have a default value set on the column in the table. Otherwise Access will throw cryptic errors.
 

Royce

Access Developer
Local time
Today, 05:26
Joined
Nov 8, 2012
Messages
99
This is an old thread, but if you set the default value of the YesNo field to 0 or 1 The Access Form Wizards will add the field as a check box to forms. When there is not a default, or the default is No or Yes then it will add it as a Text Box. (Not sure if this is true for SQL backend, but it is for Access backend.)
 

Users who are viewing this thread

Top Bottom