Results 1 to 14 of 14
  1. #1
    justair07 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2013
    Location
    Flordia
    Posts
    63

    VBA to Refresh/Requery a Form

    Hello,



    I have a form that I need to requery/refresh from the press of a cmdbutton on a different form.

    Here is what I tried but it's not working
    Code:
    Private Sub cmdSalesComp_Click()
    
    DoCmd.Requery "frmPDMonitor"
    
    End Sub
    Thank you,

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    should work, maybe add acform

    DoCmd.Requery acform, "frmPDMonitor"

  3. #3
    justair07 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2013
    Location
    Flordia
    Posts
    63
    Getting Compile error: "wrong number of arguments or invalid property assignment"

  4. #4
    justair07 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2013
    Location
    Flordia
    Posts
    63
    Does the form have to be closed for it to work? Because that would defeat the purpose. Basically this will replace the refresh button once I'm viewing the form. I want the form to refresh from a different form entirely. Does that make sense?

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Yah that is not working. The form needs to be open. Try

    Code:
    Forms!frmPDMonitor.SetFocus
    DoCmd.Requery

  6. #6
    justair07 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2013
    Location
    Flordia
    Posts
    63
    Nope, not working either. It seems like this should be so easy.

  7. #7
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I have never tried to requery a form from another form before. I tested the code in post #6 and it did not cause an exception so I will assume it is requerying the table.

    What is happening that causes you to believe the code in post #6 is not working? Perhaps saving the recordset in the original form will benefit the requery.

    Code:
    If Me.Dirty Then Me.Dirty = False
    Forms!frmTestDateNull.SetFocus
    DoCmd.Requery

  8. #8
    justair07 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2013
    Location
    Flordia
    Posts
    63
    I may be looking at this wrong. Let me explain from the beginning and maybe you can tell me.

    I have a main form that the user will enter data. Once they hit a submit button, it saves the record and I was hoping it would also refresh the form in which is linked to a query. the form that is linked to a query will be displayed on a monitor 24/7. It will display pending orders. So I was hoping as new orders are placed, the query would display them without needing to be closed and then reopened.

  9. #9
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Every workstation that opens a form will have their own instance of the form open on their local machine. Split DB's with FE and back end files vs. All in One files on a server do not change this. The workstation's OS uses its own RunTime to work with the database file.

    The requery has to happen on the workstation that has the form open. Perhaps a dedicated front end file on a dedicated workstation for the monitor displaying the form. The front end file could run a timer and the timer could determine requery.

  10. #10
    justair07 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2013
    Location
    Flordia
    Posts
    63
    Quote Originally Posted by ItsMe View Post
    Every workstation that opens a form will have their own instance of the form open on their local machine. Split DB's with FE and back end files vs. All in One files on a server do not change this. The workstation's OS uses its own RunTime to work with the database file.

    The requery has to happen on the workstation that has the form open. Perhaps a dedicated front end file on a dedicated workstation for the monitor displaying the form. The front end file could run a timer and the timer could determine requery.
    Yes, that would be perfect! I figured I had to put the form on a FE all by itself if I wanted to display it 24/7. How do I set the timer for the requery? I want to test it out.

  11. #11
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    forms have built in timer that you could use in VBA to trigger a requery

    you could build your own function and have it return a value. Maybe modify this example

    Function BeginStop(intTime As Integer)

    Dim dblCount As Double

    dblCount = DateAdd("s", intTime, Now)

    While DateDiff("s", Now, dblCount) > 0
    Wend

    MsgBox "Time is up"

    End Function

  12. #12
    justair07 is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2013
    Location
    Flordia
    Posts
    63
    Awesome thank you for all the help...

    I also found this awesome article for timers... http://mooreaboutaccess.com/2010/05/...refresh-forms/

  13. #13
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You might look here http://access.mvps.org/access/forms/frm0032.htm

    I would use something like
    (This would be in the form module "frmTestDateNull")
    Code:
    Private Sub Form_Timer()
       If isloaded("Forms!frmTestDateNull" Then
          Me.requery
       End if
    End Sub
    
    'start the clock
    Private Sub cmdClockStart_Click()
        Me.TimerInterval = 60000      ' 1 minute between requery
    End Sub
    
    'need a way to stop requiring - maybe to add/edit data
    Private Sub cmdClockEnd_Click()
        Me.TimerInterval = 0
    End Sub

    To run Visual Basic code at intervals specified by the TimerInterval property, put the code in the form's Timer event procedure. For example, to requery records every 30 seconds, put the code to requery the records in the form's Timer event procedure, and then set the TimerInterval property to 30000.

  14. #14
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Glad you are working towards a solution.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 11
    Last Post: 09-17-2012, 02:23 PM
  2. Requery vs. Refresh
    By tylerg11 in forum Forms
    Replies: 3
    Last Post: 03-28-2012, 11:54 AM
  3. Refresh Requery Subform
    By eww in forum Programming
    Replies: 1
    Last Post: 04-05-2011, 09:19 AM
  4. Dependent List Boxes do not refresh using ReQuery
    By weeblesue in forum Programming
    Replies: 2
    Last Post: 03-28-2011, 08:47 AM
  5. Access novice help with refresh/requery
    By cvacgreg in forum Access
    Replies: 3
    Last Post: 02-04-2011, 08:51 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