Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    sheusz is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2015
    Posts
    193

    Question How to "refresh" a form when it becomes active.

    Good afternoon all. I'm hoping that I can explain this clearly in order to gain some assistance.

    I have a customer form that has a button on it that, when clicked, opens a sub form showing records associated with the customer.

    Click image for larger version. 

Name:	BTN Before Press.jpg 
Views:	15 
Size:	1.6 KB 
ID:	52720


    Overlaid on the button is an unbound text box that shows the number of records in the associated subform table. This works nicely.

    The problem I have is that when I click the button, open the subform, then close the subform the unbound text box disappears. I'm guessing that it is actually now behind the button, hence obscured.


    Click image for larger version. 

Name:	BTN After Press.jpg 
Views:	15 
Size:	1.6 KB 
ID:	52721



    Is there a way that I can "refresh" the screen without requerying the customer form?

    I've tried this below, but the problem is that this causes the record pointer to move to the first record in the customer table.

    Code:
    Private Sub Form_Activate()
        Me.Requery
    End Sub
    Basically, what I am wanting is for the unbound text box to reposition over the top of the subform button.

    Thank you in advance.

  2. #2
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    430
    why are you Overlaying the the button with an Unbound textbox?
    if you want to put the Textbox in front, you can try to SetFocus on it on
    your Activate event:
    Code:
    Private Sub Form_Activate()
         Me!UnboundTextboxName.SetFocus
    End Sub

  3. #3
    davegri's Avatar
    davegri is online now Excess Access
    Windows 11 Access 2021
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,740
    I'm guessing that it is actually now behind the button, hence obscured.
    Why not temporarily separate the two, so that you can see what is happening?
    Also, your code might require the subform to be open in order for it's record count to remain in the textbox.

  4. #4
    sheusz is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2015
    Posts
    193
    Quote Originally Posted by jojowhite View Post
    why are you Overlaying the the button with an Unbound textbox?
    if you want to put the Textbox in front, you can try to SetFocus on it on
    your Activate event:
    Code:
    Private Sub Form_Activate()
         Me!UnboundTextboxName.SetFocus
    End Sub
    I'm overlaying the textbox on the button so that the user can see how many service records are associated with that customer.

    I had already tried SetFocus as you described, but the problem with this is that the textbox needs to be enabled, which I don't want. Its contents are populated on the customer forms OnCurrent event and I don't want the operator to be able to click the text box.

    Code:
    Me.txtServRecCount = DCount("[CustomerID]", "[xServices]", "[CustomerID]='" & Me.CustomerID & "'")

  5. #5
    sheusz is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2015
    Posts
    193
    Quote Originally Posted by davegri View Post
    Why not temporarily separate the two, so that you can see what is happening?
    Also, your code might require the subform to be open in order for it's record count to remain in the textbox.
    Hi davegri

    Separating the two solves the problem, but it's not as visually appealing (to me at least) as having the number of records overlayed on the button.

  6. #6
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    430
    you can totally Remove the code on the OnCurrent event by Assigning the formula as the
    ControlSource of your textbox:

    on design view of your form, click on the txtServRecCount textbox and on it's
    Property->Data->ControlSource, put:
    Code:
    =DCount("[CustomerID]", "[xServices]", "[CustomerID]='" & Nz(Me.CustomerID, 0) & "'") 
    Then remove the code on the Current Event of your form.

    With this method, the Textbox is Readonly, so users cannot
    change the value in it.

    or just add a Caption to your button and on the Activate event,
    assign the caption to it as your formula does:

    Code:
    Private Sub Form_Activate()
    Me!TheButtonName.Caption = DCount("[CustomerID]", "[xServices]", "[CustomerID]='" & Nz(Me.CustomerID, 0) & "'")
    End Sub
    
    or another possible approach is to Setfocus on Another Control (except the button) on
    your form:
    Code:
    Private Sub Form_Activate()
    'set focus on the Counting textbox
    Me.txtServRecCount.Setfocus
    'set focus on another textbox/control on the form
    Me.AnotherTextboxOnForm.Setfocus
    End Sub

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    You say you are opening and closing a subform but subforms are not "opened" and "closed", forms are. So are you actually opening and closing an independent form?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  8. #8
    sheusz is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2015
    Posts
    193
    Hi JoJo

    Thanks for your suggestions.

    I tried this as you suggested in the control source for the text box
    Code:
    =DCount("[CustomerID]", "[xServices]", "[CustomerID]='" & Nz(Me.CustomerID, 0) & "'") 

    but the text box displays Name? So there is some sort of syntax issue. (BTW CustomerID is a text field, not numeric.)

    Regardless of that, this issue remains the same.

    As for the caption option on the button. I think that because there is a bitmap on the button, captions won't work.

    I had already tried you third suggestion, but again the text boxes have to be enabled in order for SetFocus to work, no matter how briefly.


    Code:
    Private Sub Form_Activate()
    'set focus on the Counting textbox
    Me.txtServRecCount.Setfocus
    'set focus on another textbox/control on the form
    Me.AnotherTextboxOnForm.Setfocus
    End Sub
    
    But then I tried just setting the focus on another button on the form without setting focus on the textbox and that seems to have resolved the problem. Go figure.

  9. #9
    sheusz is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2015
    Posts
    193
    Quote Originally Posted by June7 View Post
    You say you are opening and closing a subform but subforms are not "opened" and "closed", forms are. So are you actually opening and closing an independent form?
    You are correct.

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Can't use Me. in a textbox expression, only in vba, so just remove it. Just a little "oops" by jojo.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  11. #11
    sheusz is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2015
    Posts
    193
    Quote Originally Posted by June7 View Post
    Can't use Me. in a textbox expression, only in vba, so just remove it. Just a little "oops" by jojo.
    OK. That did it.

    Code:
    =DCount("[CustomerID]", "[xServices]", "[CustomerID]='" & Nz(CustomerID, 0) & "'") 
    Still not sure which is the best approach.

    Using the OnCurrent event to set the value in the text box or the text box control data source. Both work, but are there benefits in one or the other?

  12. #12
    jojowhite's Avatar
    jojowhite is offline Competent Performer
    Windows 11 Access 2021
    Join Date
    Jan 2025
    Posts
    430
    then you temporarily Enable it:
    Code:
    Private Sub Form_Activate()
    'enable and setfocus
    With Me.txtServRecCount
         .Enabled = True
        .Setfocus
    End With
    'set focus on another textbox/control on the form
    Me.AnotherTextboxOnForm.Setfocus
    'disable it again
    Me.txtServRecCount.Enabled =False
    End Sub
    Name? means the controlname on the Expression is the same as that
    of the Table name, so Access is somewhat confused.

    Textbox is not the same as Fieldname, so it is good practice
    not to name your textbox same as the Fieldname where it
    is bound. You can prefix the name of the textbox with "txt" (+Fieldname).

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I have noticed domain aggregate function in textbox slowing performance of form with large dataset.

    As for setting caption property option - buttons can have an associated label control, use VBA to set its Caption. And visibility is no longer issue.

    jojo, NAME? was due to Me. in textbox expression. Since removing it fixed, circular reference was not issue.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  14. #14
    sheusz is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    May 2015
    Posts
    193
    Hi jojo and June7.

    Thank you both for your help.

    In the end the solution was simply to set focus to another button on the customer form when it become active

    Code:
    Private Sub Form_Activate()
        Me!CloseBtn.SetFocus
    End Sub
    and I will assign the value of the text box in the OnCurrent event, because I can see that the dataset will get quite large over the years.

    Code:
    Me.txtServRecCount = DCount("[CustomerID]", "[xServices]", "[CustomerID]='" & Nz(Me.CustomerID, 0) & "'")

  15. #15
    June7's Avatar
    June7 is offline VIP
    Windows 11 Access 2021
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    More specifically, I noticed a lag in Domain Aggregate calculation refreshing when navigating records.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 9
    Last Post: 11-22-2018, 12:46 AM
  2. Replies: 7
    Last Post: 02-07-2014, 11:13 AM
  3. Replies: 21
    Last Post: 01-21-2014, 05:04 PM
  4. Replies: 1
    Last Post: 01-11-2014, 12:39 PM
  5. Replies: 1
    Last Post: 07-14-2010, 11:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums