New record not shown in report until move to different record and back

X

xg

I have frmStudent with a subform to allow adding new record. When click this
button on the subform, newly added record is not shown in the report even
with my Me.Dirty = False.

If I close this frmStudent and return to frmMainMenu, come back, locate the
record and click this button, the newly added record would show in the
report. How to fix it? Thanks.

Private Sub cmdPreviewCourse_Click()
On Error GoTo Err_cmdPreviewCourse_Click

Dim strDocName As String
Dim strWhere As String

strDocName = "rptMyProgram"
strWhere = "(stID Is Null) OR ([stID]=""" & Me!stID & """)"
Me.Dirty = False
DoCmd.OpenReport strDocName, acPreview, , strWhere

Exit_cmdPreviewCourse_Click:
Exit Sub

Err_cmdPreviewCourse_Click:
If Err.Number = 2501 Then ' ignore cancel event error
Else
MsgBox Err.Description
End If
Resume Exit_cmdPreviewCourse_Click

End Sub
 
S

strive4peace

Hi firstly, in case your record has not changed, you should
do this

if me.dirty then Me.Dirty = False

what is your report based on? If it is based on a query
that is open, then that query needs to be updated.

is StID defined to be a text field in your table design?

Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
 
X

xg

Yes, the report is based on query. How to update query in code?
stID is text field

thanks

strive4peace said:
Hi firstly, in case your record has not changed, you should do this

if me.dirty then Me.Dirty = False

what is your report based on? If it is based on a query that is open,
then that query needs to be updated.

is StID defined to be a text field in your table design?

Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
I have frmStudent with a subform to allow adding new record. When click
this button on the subform, newly added record is not shown in the report
even with my Me.Dirty = False.

If I close this frmStudent and return to frmMainMenu, come back, locate
the record and click this button, the newly added record would show in
the report. How to fix it? Thanks.

Private Sub cmdPreviewCourse_Click()
On Error GoTo Err_cmdPreviewCourse_Click

Dim strDocName As String
Dim strWhere As String

strDocName = "rptMyProgram"
strWhere = "(stID Is Null) OR ([stID]=""" & Me!stID & """)"
Me.Dirty = False
DoCmd.OpenReport strDocName, acPreview, , strWhere

Exit_cmdPreviewCourse_Click:
Exit Sub

Err_cmdPreviewCourse_Click:
If Err.Number = 2501 Then ' ignore cancel event error
Else
MsgBox Err.Description
End If
Resume Exit_cmdPreviewCourse_Click

End Sub
 
S

strive4peace

Is the query is open and being used?

if it IS open, you can try requerying whatever is using it.

ie: forms!formname.requery

but you would have to make sure that form is in a state
where it CAN be requeried. If it has a record that needs to
be saved, save it and then requery:

'~~~~~~~~~~~~~~~~~
if forms!formnane.dirty then
forms!formnane.dirty = false
forms!formname.requery
DoEvents
end if
'~~~~~~~~~~~~~~~~~

if you still have troubles, I would suggest that you try
using the WhereClause parameter of the OpenReport action
instead of putting criteria in your query

Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
Yes, the report is based on query. How to update query in code?
stID is text field

thanks

Hi firstly, in case your record has not changed, you should do this

if me.dirty then Me.Dirty = False

what is your report based on? If it is based on a query that is open,
then that query needs to be updated.

is StID defined to be a text field in your table design?

Warm Regards,
Crystal
Microsoft Access MVP 2006

*
Have an awesome day ;)

remote programming and training
strive4peace2006 at yahoo.com

*
I have frmStudent with a subform to allow adding new record. When click
this button on the subform, newly added record is not shown in the report
even with my Me.Dirty = False.

If I close this frmStudent and return to frmMainMenu, come back, locate
the record and click this button, the newly added record would show in
the report. How to fix it? Thanks.

Private Sub cmdPreviewCourse_Click()
On Error GoTo Err_cmdPreviewCourse_Click

Dim strDocName As String
Dim strWhere As String

strDocName = "rptMyProgram"
strWhere = "(stID Is Null) OR ([stID]=""" & Me!stID & """)"
Me.Dirty = False
DoCmd.OpenReport strDocName, acPreview, , strWhere

Exit_cmdPreviewCourse_Click:
Exit Sub

Err_cmdPreviewCourse_Click:
If Err.Number = 2501 Then ' ignore cancel event error
Else
MsgBox Err.Description
End If
Resume Exit_cmdPreviewCourse_Click

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top