Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help: Refreshing query record on Form Automatically

Status
Not open for further replies.

RDMRDM

Programmer
Apr 9, 2007
33
US
I have a form that has a list box. Within that list box, it is tied to a query. When I change a record on the form that is tied to that query and go to the next record, this query does not update my totals. If I go up to menu and select Records, then Refresh, it will update the form to show the new query results. It also updates once I close and reopen database. Is there a way to automatically refresh once I change records? Thanks in advance.
 
Add a line of code to the After Update event for the control and the Current event for the form:

[tt]Me.Requery[/tt]
 
I must be doing something wrong. I went into the list box and found the "After Update" field. I went into the expression builder and and selected Code builder. At the bottom of the code, I inserted the Me.Requery as follows:

Private Sub List232_AfterUpdate()
Me.Requery
End Sub

Where would I find the Current Event you are talking about? Sorry about not understanding the coding in detail so much, this is kind of new to me. Thanks for your help.
 
The Current event belongs to the form. Click on the little box in the top left hand corner of the form (design view) to select the form.
 
Found that, do I just insert Me.Requery where the expression builder takes me? When I did that and went back to my form, it was refreshing for about 8 seconds for each record I went to. Any ideas? Thanks again for all your help.
 
Is this a continuous form? Also, please post your code.
 
When I go to the form, and select On Current field and select Code Builder, here is where it takes me. Note: This is where the default takes me to when it opens the code. This is the part that defaults to insert:

Private Sub Form_Current()

End Sub

Here is all the code. Let me know where I should put the Me.Requery if you happen to know. Thanks.


Option Compare Database


Private Sub DialContact_Click()
On Error GoTo Err_Dial_Click

Dim strDialStr As String
Dim ctlPrevCtl As Control
Const ERR_OBJNOTEXIST = 2467
Const ERR_OBJNOTSET = 91

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Set ctlPrevCtl = Screen.PreviousControl

If TypeOf ctlPrevCtl Is TextBox Then
strDialStr = IIf(VarType(ctlPrevCtl) > V_NULL, ctlPrevCtl, "")
ElseIf TypeOf ctlPrevCtl Is ListBox Then
strDialStr = IIf(VarType(ctlPrevCtl) > V_NULL, ctlPrevCtl, "")
ElseIf TypeOf ctlPrevCtl Is ComboBox Then
strDialStr = IIf(VarType(ctlPrevCtl) > V_NULL, ctlPrevCtl, "")
Else
strDialStr = ""
End If

Application.Run "utility.wlib_AutoDial", strDialStr

Exit_Dial_Click:
Exit Sub

Err_Dial_Click:
If (Err = ERR_OBJNOTEXIST) Or (Err = ERR_OBJNOTSET) Then
Resume Next
End If
MsgBox Err.Description
Resume Exit_Dial_Click
End Sub

Private Sub Form_Current()

End Sub

Private Sub List219_AfterUpdate()
' Find the record that matches the control.
Dim rs As Object

Set rs = Me.Recordset.Clone
rs.FindFirst "[ContactID] = " & Str(Nz(Me![List219], 0))
If Not rs.EOF Then Me.Bookmark = rs.Bookmark
End Sub
 
The listbox you show is simply a means of finding a record, but I am now not quite sure about totals you refer to. How are these total obtained? It is possible that you need a Recalc, rather than a requery.
 
the list box that I am trying to refresh is tied to a query, so I thought the query needed to refresh using a requery. Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top