Update value of VBA variable on a form in text box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all

I can get the variable to display on the form but only after the module code
has completed running the procedure or after I insert a msgbox in the code.
How can I get the value of the variable to display in the text box as soon as
it gets calculated?

I'm also having the same trouble updating the colour property of a rectangle
control on the form while the VBA code is executing.

This sounds like it should be very simple, but it has me baffled.
 
Norm said:
I can get the variable to display on the form but only after the module code
has completed running the procedure or after I insert a msgbox in the code.
How can I get the value of the variable to display in the text box as soon as
it gets calculated?

I'm also having the same trouble updating the colour property of a rectangle
control on the form while the VBA code is executing.


Try using Me.Repaint after changing the text box's value anf
the rectangle's BackColor.

If that doesn't do it, try adding a DoEvents after the
Repaint.
 
I knew this should be easy. That was awesome. We've only got it half right
so far. The rectangles changed colours as I had hoped - it was very
refreshing to watch BTW.

If you have any ideas on how to get the variable data to display at the same
time, I'll gladly give them a try. In the meantime I'll put some comments to
the code and will post it for reference.

Thanks
Norm
 
Sorry for the length, but I'm trying to help you help me.

Option Compare Database
Option Explicit
Dim x, StopError
Dim IntervalTime As Single


Public RunTime As Single
Public Start As Single
Public EndTime As Single


Public clrGRN
Public clrYEL
Public clrRED

Dim MSComm As Object ' Serial port as inputs monitoring lap counts

Public Function GetStartTimer() As Single
GetStartTimer = Start
End Function

Public Function GetRunTime() As Single
GetRunTime = RunTime
End Function

'This function is here because I couldn't get
'the functions GetStartTimer() and GetRunTime()
'to display their values without it(????)
Public Function ScreenUpdate()
Forms("form1").Refresh
End Function

Public Sub StartRace()

' all rectangles start out yellow
clrGRN = 65280
clrYEL = 65535
clrRED = 255

' Each rectangle will turn Green in sequence
' in the interval time specified

IntervalTime = 1 ' Seconds

For x = 1 To 5

' Timer = number of seconds since last midnight (microSeconds)
Start = Timer

'The rectangles and text boxes are on "Form1".
'For now I would like to be able to display the "Start" variable
'on "Form1" as each rectangle turns green. If I can do that I can
easily
'Display the lap times

EndTime = Start + IntervalTime

Do While Timer < EndTime

Loop


If x = 1 Then Forms("Form1").Box7.BackColor = clrGRN
If x = 2 Then Forms("Form1").Box13.BackColor = clrGRN
If x = 3 Then Forms("Form1").Box14.BackColor = clrGRN
If x = 4 Then Forms("Form1").Box17.BackColor = clrGRN
If x = 5 Then Forms("Form1").Box18.BackColor = clrGRN

'Try to get variables to update on "Form1"
Call ScreenUpdate

'This repaint worked wonders on the rectangle colour changes
Forms("form1").Repaint

Next x

End Sub
 
I think you're saying that you're having trouble with the
code in the ScreenUpdate procedure, but you didn't post that
code. It's probably as simple as something like
Forms("form1").sometextbox = Start

If so, I would have expected the Repaint to take care of it,
but sometimes it isn't enough. Try adding one or more
DoEvents:

Forms("form1").Repaint
DoEvents
 
THANK YOU, Thank you, thank you.
Here is the SCREENUPDATE code that finally worked

' Call the functions that update the text boxes
GetStartTimer
GetRunTime

' This DoEvents was required - no update without it.
DoEvents

' This refresh had to be there otherwise there was no data update
even after the sub procedure completed.
Forms("form1").Refresh

' This RePaint alone updated the rectangle colours
Forms("form1").Repaint

' Without this DoEvents the text boxes would not display
anything until
the sub procedure completed.
DoEvents


I don't know why it works, but I'm very glad it will work now.

Norm


Marshall Barton said:
I think you're saying that you're having trouble with the
code in the ScreenUpdate procedure, but you didn't post that
code. It's probably as simple as something like
Forms("form1").sometextbox = Start

If so, I would have expected the Repaint to take care of it,
but sometimes it isn't enough. Try adding one or more
DoEvents:

Forms("form1").Repaint
DoEvents
--
Marsh
MVP [MS Access]

Sorry for the length, but I'm trying to help you help me.

Option Compare Database
Option Explicit
Dim x, StopError
Dim IntervalTime As Single


Public RunTime As Single
Public Start As Single
Public EndTime As Single


Public clrGRN
Public clrYEL
Public clrRED

Dim MSComm As Object ' Serial port as inputs monitoring lap counts

Public Function GetStartTimer() As Single
GetStartTimer = Start
End Function

Public Function GetRunTime() As Single
GetRunTime = RunTime
End Function

'This function is here because I couldn't get
'the functions GetStartTimer() and GetRunTime()
'to display their values without it(????)
Public Function ScreenUpdate()
Forms("form1").Refresh
End Function

Public Sub StartRace()

' all rectangles start out yellow
clrGRN = 65280
clrYEL = 65535
clrRED = 255

' Each rectangle will turn Green in sequence
' in the interval time specified

IntervalTime = 1 ' Seconds

For x = 1 To 5

' Timer = number of seconds since last midnight (microSeconds)
Start = Timer

'The rectangles and text boxes are on "Form1".
'For now I would like to be able to display the "Start" variable
'on "Form1" as each rectangle turns green. If I can do that I can
easily
'Display the lap times

EndTime = Start + IntervalTime

Do While Timer < EndTime

Loop


If x = 1 Then Forms("Form1").Box7.BackColor = clrGRN
If x = 2 Then Forms("Form1").Box13.BackColor = clrGRN
If x = 3 Then Forms("Form1").Box14.BackColor = clrGRN
If x = 4 Then Forms("Form1").Box17.BackColor = clrGRN
If x = 5 Then Forms("Form1").Box18.BackColor = clrGRN

'Try to get variables to update on "Form1"
Call ScreenUpdate

'This repaint worked wonders on the rectangle colour changes
Forms("form1").Repaint

Next x

End Sub
 
Back
Top