Refresh Userform during whilst code is running.

StevenD

Active Member
Joined
Nov 17, 2004
Messages
262
Hi,

I have a userform that I want to update as soon as the code requests it, but unfortunately because the code is still looping back around it doesn't update the userform until the code has completed.

Is there a way i can force a refresh?

Attached is the code that I want to use.

Code:
Public Sub CheckCollation()
CheckingCollation = True
MainForm.Info.Caption = "Collate All QR Codes"
ScanAgain:
Readers.QRCode.InputLen = 0
QRReading = ""
Do Until QRReading <> "" And Len(QRReading) = 6
    QRReading = Readers.QRCode.InputData
Loop
a = Len(QRReading)
QRReading = Left(QRReading, a - 1)

For a = 1 To 6
    If MainForm.Controls("QRModel" & a).Caption = QRReading Then
        MainForm.Controls("collated" & a).Caption = "a"
           Exit For
    Else
    End If
Next a
'Check all collated
CollatedAll = True
For a = 1 To 6
    If MainForm.Controls("collated" & a).Visible = True Then
        If MainForm.Controls("collated" & a).Caption = "r" Then
            CollatedAll = False
        End If
    End If
Next a
If CollatedAll = True Then AllCollated = True
If AllCollated = False Then GoTo ScanAgain
End sub
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

hatman

Well-known Member
Joined
Apr 8, 2005
Messages
2,664
I don't see where you change any info on your userform in your code... but whenever you do change info and want it visible, you should be able to use the DoEvents command to refresh the userform.
 

StevenD

Active Member
Joined
Nov 17, 2004
Messages
262
Hi,

Thanks for the reply.

The line of code that changes part of the userform is.

MainForm.Controls("collated" & a).Caption = "a"

Basically the "a" in webdings represents a tick in a label. What the code does is looks at what is input via the serial port and tries to match it to 6 labels on the form. If it finds a match then it changes the label next to the corresponding label to a tick.

If there are 3 to match then it cycles until the 3 are matched, unfortunately it doesn't update the userform with the ticks until all 3 are matched.

Would repaint do this?
 

hatman

Well-known Member
Joined
Apr 8, 2005
Messages
2,664
I forgt about repaint... I believe that you could use either Mainform.repaint or DoEvents... try one then the other, immediately after the line that changes the form, and see which one works...
 

Forum statistics

Threads
1,137,332
Messages
5,680,875
Members
419,937
Latest member
Talic

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top