Me. refresh not working (1 Viewer)

tweetyksc

Registered User.
Local time
Today, 03:46
Joined
Aug 23, 2001
Messages
87
Has anyone experienced problems with Me.Refresh not working?
I have a couple procedures on a form where the form needs to refresh after running code. For one procedure, it always works. For the other, it doesn't.
I need this primarily to update a field that shows the number of records in a table (Dcount). This should show a number of records after the first procedure (importing) and change to zero after the second (rolling up to the YTD table). Or is it because I am testing and running both procedures one after another (in the user environment, they wouldn't be doing that).
Grasping at straws to figure it out...

Here's the code (abbreviated):

************************************
Private Sub cmdRollUp_Click()
On Error GoTo Err_cmdRollUp_Click

DoCmd.SetWarnings False
If MsgBox("Data will be moved from Proof/Commission tables to YTD tables. Current tables will be cleared (along with BP table). Continue?", vbYesNo, "Are you sure?") = vbNo Then
Exit Sub
Else
***[multiple queries run to update the tables; these do run fine]***
MsgBox "RollUp Complete! Sales Rep report will appear if new sales reps were found", vbOKOnly, "Roll-Up Data"
DoCmd.OpenReport "SalesReps", acViewPreview, , "[salesrep] is null"
End If

DoCmd.SetWarnings True
Me.Refresh ***[this one does not work. ]****

Exit_cmdRollUp_Click:
Exit Sub

Err_cmdRollUp_Click:
If Err.Number = 2501 Then
Else
MsgBox Err.Number & "-" & Err.Description
End If
Resume Exit_cmdRollUp_Click

End Sub
'---------------------------------------------------------

Private Sub cmdImport_Click()
On Error GoTo Err_cmdImport_Click

Dim strqueryname As String
Dim strobjectname As String
Dim strtable As String
Dim intcount As Integer

DoCmd.SetWarnings False

Select Case optImport
Case 1
**code**
Case 2
**code**
Case 3
**code**
End Select

If intcount > 0 Then
MsgBox strtable & " should be rolled up to YTD before importing new data", vbExclamation, strtable & " table is not empty!"
Exit Sub
End If

If MsgBox("Are you sure you want to import new " & strtable & " data?", vbYesNo, "Import " & strtable & " data") = vbYes Then
DoCmd.RunCommand acCmdImport
DoCmd.OpenQuery strqueryname
DoCmd.DeleteObject acTable, strobjectname
MsgBox "Import of " & strtable & " data is complete!", vbOKOnly, strtable & " Import"
Else
Exit Sub
End If

DoCmd.SetWarnings True
Me.Refresh **[this works ]***

Exit_cmdImport_Click:
Exit Sub
 

Liv Manto

Registered User.
Local time
Today, 03:46
Joined
Apr 26, 2001
Messages
266
DoCmd.OpenReport "SalesReps", acViewPreview, , "[salesrep] is null"
End If

DoCmd.SetWarnings True
Me.Refresh ***[this one does not work. ]****



Your present object that has focus on is the report?
 

puthenveetil

Registered User.
Local time
Today, 08:16
Joined
Aug 9, 2004
Messages
94
Hi,

I have the same problem too..how can I get rid of this problem.

thanks
 

RoyVidar

Registered User.
Local time
Today, 04:46
Joined
Sep 25, 2000
Messages
805
If you go to the helpfiles, the refresh method of a form is supposed to refresh the recordsource of a form. As explained, it will show updates in records that where in the forms recordset, but not show any added records, and probably not show (or remove) deleted records.

If this is what is required - a refresh of the forms recordsource, refresh will most often work as described.

If there are additions to the form recordset, or deletes, you may need to investigate the .Requery method of the form recordset, which will requery, and most often display added/deleted records correctly. It also usually resets current record (goes to the first record).

So, what does "this does not work" mean - doesn't the report populate correctly, or is it the form?

BTW for calculations (calculated controls), you may try Me.Recalc. Or if the count is supposed to be from the form recordset, you could try something like this in a relevant event:

me!txtCount.value = me.recordsetclone.recordcount

if it doesn't work, you could try:
dim rs as dao.recordset
set rs=me.recordsetclone
if not rs.bof and not rs.eof then
rs.movelast
me!txtCount.value = me.recordsetclone.recordcount
else
me!txtCount.value = 0
end if
set rs=nothing

- air code, typed not tested
 

tweetyksc

Registered User.
Local time
Today, 03:46
Joined
Aug 23, 2001
Messages
87
Got it working

I tried playing around with the replacement of the me.refresh line
and it is now working.
I'm posting this in case someone is having similar problems.

-------------------------------------------------------
If MsgBox[message box data] = vbNo Then
Exit Sub
Else
[multiple queries run to append/delete data]
me.refresh ***moved it here and it now works***
MsgBox "RollUp Complete! Sales Rep report will appear if new sales reps were found", vbOKOnly, "Roll-Up Data"
DoCmd.OpenReport "SalesReps", acViewPreview, , "[salesrep] is null"
End If

DoCmd.SetWarnings True
Me.Refresh ***[old position of statement]****
Exit_cmdRollUp_Click:
Exit Sub
--------------------------------------
I found that the refresh worked IF there were new reps added to the table (and thus a report appeared); but, if there were no new reps (report did not appear), the refresh did not work. I moved it to before the message box "rollup complete" and it now works whether the report appears or not.

RoyVidar--by not work, I mean that there are text boxes on the form with "dcount" to show the # of records in the "current" tables. This is
so the user can see at a glance if data resides in those.
This function essentially takes data in "current" tables, appends them to ytd tables, deletes the data in the current tables, updates the sales rep table,
and displays a report if new sales rep was found. The "dcount" text boxes refresh to show the count of records when new data is brought into the database from this form (that was working fine); it also refresh to show 0 after the "rollup" is done.
 

Users who are viewing this thread

Top Bottom