Refresh Captions (2 Viewers)

Archie999

Access Wannabee
Local time
Today, 04:21
Joined
May 25, 2003
Messages
45
Hello All,

I have a caption on my form that is attached to an option button. I have the form coded so that this caption has it's value depend on a field on the same form.

I actually got it to work but if I change the value of the control field that the caption depends on, I would like the caption to update itself immediatley. This part does not work. I have tried updating and refreshing the form but the caption does not change.

I have the following code in the 'On Current' event of the form as well as the 'After Update' field of the control field.

Private Sub SiteID_AfterUpdate()
' Set Owner Caption to site's initials
Dim OwnerCaption As Variant
OwnerCaption = DLookup("SiteInitials", "tblSite", "[SiteID] = " _
& Me.SiteID)
If IsNull(Me.SiteID) Then
Me.lblOrgOwnerSite.Caption = "Site"
Else
Me.lblOrgOwnerSite.Caption = OwnerCaption
End If
' Requery the Owner Caption
Me.Refresh

The last 2 lines were my attempt to refresh but it did not work.

Anyone have any ideas of how to refresh the caption on a form (or note any problem with the code).

Thanks very much!

Arch
 
What you want to do is not Requery. After the field is updated, you would use your code to set the value of the caption and then use a Me.Repaint and that should take care of it for you.
 
Variable not updated at all

Hi,

Thanks for your response Bob. Although this did not resolve my problem, I'm sure that it will work once I've figured this out.

Here is the problem now. In troubleshooting it seems that the issue is that my variable 'OwnerCaption' is not being updated at all. Regardless of the value of 'SiteID' (which does change) the value of OwnerCaption remains the same after the code has been run once. So, it worked the first time and now it's stuck.

Do I need to somehow reset the variable so that it will be re-populated with a new value? This seems to be the offending code. Appreciate any input. Thanks again all!

Dim OwnerCaption As Variant
OwnerCaption = DLookup("SiteInitials", "tblSite", "[SiteID] = " _
& Me.SiteID)
 
This may not have anything to do with your problem, but I can see one thing that, if not offending here, may cause you grief in other ways. You need to rename your control something other than the same as the field in the table.

So, for example, your SiteID textbox would be named txtSiteID. It's amazing that Microsoft, in their infinite weirdness, violate that same principle with their forms wizard, which creates the textboxes, etc and names them the same as the field. And yet, if you do, it can cause problems in various ways.

So, I'm not sure what the problem is. One other thing to note, is that you were asking if you needed to reset the variable. Actually, since you are using it as private from within a form module, it is only good for the one instance that it happens and it doesn't hold the value. You've declared another instance of it from within the After_Update event and so it is a totally separate item than the one you used in your other code.
 

Users who are viewing this thread

Back
Top Bottom