Progress Bar for Counting Checkboxes (1 Viewer)

KriXx

New member
Local time
Yesterday, 18:07
Joined
May 24, 2017
Messages
4
Gurus,

Appreciate if you can point me the right direction on creating a progress bar similar to the link below.

codepen.io/jamesbarnett/pen/ybvLB

I have tried several examples but struggling on VBA to make it work.

Thank you in advance.

Cris
 

Ranman256

Well-known member
Local time
Yesterday, 21:07
Joined
Apr 9, 2015
Messages
4,339
Do you want to count checkboxes on a form?
Or in a table?
I don't see it being productive. It would take a second,unless you are counting a million.
 

KriXx

New member
Local time
Yesterday, 18:07
Joined
May 24, 2017
Messages
4
Do you want to count checkboxes on a form?
Or in a table?
I don't see it being productive. It would take a second,unless you are counting a million.

On a form. I am doing a report that for any completed project or task the checkbox needs to be ticked. Based on the number of boxes ticked I will have a progress bar on top.

I am working on the logic of this code and see if I can convert to VBA. But, any help I would appreciate.

Code:
Private Sub Form_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        ProgressBar1.Maximum = 3
    End Sub

    Private Sub CheckBox_CheckedChanged(sender As Object, e As EventArgs) Handles _
        CheckBox1.CheckedChanged, _
        CheckBox2.CheckedChanged, _
        CheckBox3.CheckedChanged

        Dim Count As Integer = 0
        If CheckBox1.Checked Then Count += 1
        If CheckBox2.Checked Then Count += 1
        If CheckBox3.Checked Then Count += 1

        Progressbar1.value = Count

    End Sub
 

KriXx

New member
Local time
Yesterday, 18:07
Joined
May 24, 2017
Messages
4
Thank You Uncle Gizmo. I have a similar code in the video that I use that when a text box value is zero it will not be clickable.

Code:
Private Sub Form_Current()
Dim ctl As Control
For Each ctl In Me
    If TypeOf ctl Is TextBox Or TypeOf ctl Is ComboBox Then
        If Nz(ctl, "") = 0 Then
            ctl.Enabled = False
        End If
    End If
Next
End Sub

I will use your 2nd example on check boxes and see if it will sort me out. Again, thank you.
 
Last edited:

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 02:07
Joined
Jul 9, 2003
Messages
16,273
Just bare in mind that if you have any other check boxes on the form it will also process those. There are several ways to group various controls. One way is putting something in the tag property of the control.

Sent from my SM-G925F using Tapatalk
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 02:07
Joined
Jul 9, 2003
Messages
16,273
If you are going to adapt the code you posted I suggest you change this line from:-

Code:
For Each ctl In Me

To:-

Code:
For Each ctl In Me.Controls

I'm not sure if it makes any significant difference, but it's the way that it's normally done.
 

Cronk

Registered User.
Local time
Today, 11:07
Joined
Jul 4, 2013
Messages
2,771
Incidentally,
Code:
Count +=1
is not valid syntax in vba
Use
Code:
Count = count + 1
Actually, count is a reserved word. I'd rename the variable to say, intCount

As to displaying a progress bar, you can use Access's internal progress bar - lookup
cmdsys(acsysCmdInitMeter....)

or create your own bar by adding a rectangle to your form and setting the width.

ie
Code:
 me.bxRectangle.width = intCount*567
will set the bar to intCount centimeters
 

Users who are viewing this thread

Top Bottom