Refresh a textbox

Stoss

Registered User.
Local time
Today, 14:37
Joined
Nov 5, 2010
Messages
107
I run a function from "Current" event on form2. This sets up different text boxes with the proper information for that record. On that form I have a drop down menu that changes what would be shown in those text boxes. To clarify, on current form, function sets text boxes. On the same form is where you set/change what is in those boxes.

So, if I change the drop down menu, the text box does not update, but if I go to the next record and then back, it shows the update. Just wondering the best way to refresh the current form and is that what I want to do.

-Stoss
 
I'm guessing you're using a recordset to make these changes? Why are you needing to use code to update the textboxes?

Can we see the code?
 
I am using a function because it has a some date manipulation in it and more importantly, I also use the same code for some other reports. So, instead of having basically the same code in multiple spots, I put it in Module1 to access it from these different areas.

Here is a same of some of the code. On the "Current" event I call that function with Call Priorities(strPriority, Date, ctrl)

Code:
    If strPriority = "Priority 1 (Immediately)" Then
        ctrl = "This discrepancy must be fixed IMMEDIATELY!"

        'Sets Priority 2 Priorities
        ElseIf strPriority = "Priority 2 (7-Days)" Then
            If (OpenDate + 7) > Date Then
                ctrl = "This discrepancy is " & DateDiff("d", OpenDate, Date) & " day(s) old and must be closed by " & DateAdd("d", DateDiff("d", Date - 7, OpenDate), Date) & ".  (" & DateDiff("d", Date - 7, OpenDate) & " day(s) remaining)"
            ElseIf (OpenDate + 7) = Date Then
                ctrl = "This discrepancy is due today!"
            Else
                ctrl = "This discrepancy is past due by " & DateDiff("d", OpenDate + 7, Date) & " day(s)."
            End If

Thanks,
Stoss
 
Sorry, the call is actually
Call Priorities(strPriority, myDate, Me.txtClosedBy)
 
Just below all the update code, put Forms("NameOfForm").Repaint

I don't know how you're referencing the form so amend that to suit.
 
Thanks for your help on this one. I am going to have to dig into this on my own I think. It is probably too complicated to explain well. I don't think it is that hard, just have to figure out the best way to do it.

I really don't want to take up your time on this one, you have helped me more than you know and I really appreciate it.

Thanks,
Stoss
 
That's fine. So did the repaint not work?

Are you updating bound controls right?
 
Repaint did not work.

The textbox that gets updated is unbound. The value is set by the function when I call it in the Current Event. I pass me.txtClosedBy as a parameter so it knows what control is to set with the proper value (i.e. which priority was set(that is a bound control) and then calcs the date manipulation).

In a nutshell, the textbox is just there to display different date manipulation based off of the priority that was set for the record.

So, I pass the Priority string, I pass the [Date Open], and I pass the control name "Me.txtClosedBy"

-Stoss
 
I did get it to work just by calling the function from the PRIORITY_AfterUpdate()

Code:
Dim strPriority As String
    strPriority = Me.PRIORITY

    Dim myDate As Date
    myDate = [OPEN_DATE]

    Call Priorities(strPriority, myDate, Me.txtClosedBy)

I was just hoping there was a cleaner way. What I mean by that is to do a current form run again.

-Stoss
 
The Current event has nothing to do with the the Combo box's After Update event which is why it wasn't working. Now, because the value was already set before you moved to the next record, when you come back to that record it will show the correct value.

If you want a control to update after making a change to a combo box value, you have to use the Combo box's After Update event ;)
 
Correct, the current event is to set the textbox when you go through the records. The after event on the combo box is just in case someone want to change the "priority" of the record being displayed at that time.

So, I guess the only way to do it is to run the function from the after event (as well) (in case someone changes the priority).
 
That's right, that implies you need it on the After Update event of the combo box and the Current event of the form.
 
Repaint does nothing for data. You should have said RECALC not REPAINT. Repaint handles the graphical parts.
Good point Bob, but this is not the case. The OP doesn't have calculated controls which if it did, Recalc would have been the option. The controls' values are updated via a function and hence, a repaint may have worked.

Here's an excerpt from the help file re the Repaint method:

The Repaint method completes any pending screen updates for a specified form . When performed on a form, the Repaint method also completes any pending recalculations of the form's controls .
 
I've never seen it work reliably for updating a form. And the thing to remember is that Access help isn't always correct. :)
 
True, I don't always trust the Access help either, although it's useful as a guideline though :) But I've seen Repaint work in similar cases, but those were on custom controls.
 

Users who are viewing this thread

Back
Top Bottom