By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,224 Members | 1,309 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,224 IT Pros & Developers. It's quick & easy.

How do I force a write of the data to a table?

P: n/a
I've got a very simple database, with a report that the user wants to
be able to print for a single record immediately after entering the
data.

I've created a button on the data entry form that will open the report
and print the data for the current record - but it prints a blank
record if the user hasn't left the record and returned, since leaving
the record forces the writing of the data to the table.

Is there a way to force a write to the table in VB (or any other way)
so that when the user clicks to bring up the report, it will actually
be populated with data, without having to do the moving about??

Jerry Hull
Starship Enterprises
Nov 13 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Set the Dirty property of the form to No. Example:

Private Sub cmdPrint_Click()
Dim strWhere As String

If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If

If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[ID] = " & Me.[ID]
DoCmd.OpenReport "MyReport", acViewPreview, , strWhere
End If
End Sub--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Jerry Hull" <st******@peak.org> wrote in message
news:58**************************@posting.google.c om...
I've got a very simple database, with a report that the user wants to
be able to print for a single record immediately after entering the
data.

I've created a button on the data entry form that will open the report
and print the data for the current record - but it prints a blank
record if the user hasn't left the record and returned, since leaving
the record forces the writing of the data to the table.

Is there a way to force a write to the table in VB (or any other way)
so that when the user clicks to bring up the report, it will actually
be populated with data, without having to do the moving about??

Jerry Hull
Starship Enterprises

Nov 13 '05 #2

P: n/a
Why not the following

Private Sub cmdPrint_Click()
Dim strWhere As String

If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If

If Me.NewRecord Then 'Save the new record
DoCmd.RunCommand acCmdSaveRecord
End If

strWhere = "[ID] = " & Me.[ID]
DoCmd.OpenReport "MyReport", acViewPreview, , strWhere

End Sub

This way the new record is immediately saved and then can be printed. I'd
prefer to prompt the user with a message asking if they want to save the
changes if the record is dirty rather than set the dirty property to false.

Jeff

"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:41***********************@per-qv1-newsreader-01.iinet.net.au...
Set the Dirty property of the form to No. Example:

Private Sub cmdPrint_Click()
Dim strWhere As String

If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If

If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[ID] = " & Me.[ID]
DoCmd.OpenReport "MyReport", acViewPreview, , strWhere
End If
End Sub--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Jerry Hull" <st******@peak.org> wrote in message
news:58**************************@posting.google.c om...
I've got a very simple database, with a report that the user wants to
be able to print for a single record immediately after entering the
data.

I've created a button on the data entry form that will open the report
and print the data for the current record - but it prints a blank
record if the user hasn't left the record and returned, since leaving
the record forces the writing of the data to the table.

Is there a way to force a write to the table in VB (or any other way)
so that when the user clicks to bring up the report, it will actually
be populated with data, without having to do the moving about??

Jerry Hull
Starship Enterprises


Nov 13 '05 #3

P: n/a
If it is a new record that has been entered but not saved, setting the
form's Dirty property will save it. Now it's a saved record, not a new one,
so the form's NewRecord property is no longer true.

Of course, the form could have been at a new record without anything being
entered. In that case, Dirty is not True, and so no save is performed. You
still need to test if it's a new record though, because you cannot print a
non-existent record.

If you want to prompt the user before the record is saved, use the Before
Update event of the form. That's the only way you can guarantee the user
will get the prompt regardless of how the save occurs (e.g. Save Record on
Records menu, Shift+Enter, close the form, filter the form, change the
OrderBy, and so on.)

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Jeff Smith" <No****@Not.This.Address> wrote in message
news:co**********@lust.ihug.co.nz...
Why not the following

Private Sub cmdPrint_Click()
Dim strWhere As String

If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If

If Me.NewRecord Then 'Save the new record
DoCmd.RunCommand acCmdSaveRecord
End If

strWhere = "[ID] = " & Me.[ID]
DoCmd.OpenReport "MyReport", acViewPreview, , strWhere

End Sub

This way the new record is immediately saved and then can be printed. I'd
prefer to prompt the user with a message asking if they want to save the
changes if the record is dirty rather than set the dirty property to
false.

Jeff

"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:41***********************@per-qv1-newsreader-01.iinet.net.au...
Set the Dirty property of the form to No. Example:

Private Sub cmdPrint_Click()
Dim strWhere As String

If Me.Dirty Then 'Save any edits.
Me.Dirty = False
End If

If Me.NewRecord Then 'Check there is a record to print
MsgBox "Select a record to print"
Else
strWhere = "[ID] = " & Me.[ID]
DoCmd.OpenReport "MyReport", acViewPreview, , strWhere
End If
End Sub--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Jerry Hull" <st******@peak.org> wrote in message
news:58**************************@posting.google.c om...
> I've got a very simple database, with a report that the user wants to
> be able to print for a single record immediately after entering the
> data.
>
> I've created a button on the data entry form that will open the report
> and print the data for the current record - but it prints a blank
> record if the user hasn't left the record and returned, since leaving
> the record forces the writing of the data to the table.
>
> Is there a way to force a write to the table in VB (or any other way)
> so that when the user clicks to bring up the report, it will actually
> be populated with data, without having to do the moving about??
>
> Jerry Hull
> Starship Enterprises



Nov 13 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.