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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

acSaveRecord prior to OpenReport 2

Status
Not open for further replies.

nastar1

Technical User
Nov 1, 2005
122
US
WHen I click the cmdButton with the code below the first time on a new record, the save processes, but the OpenReport does not. If the user clicks the cmdButton a 2nd time, the OpenReport works. Any tips on what I've done wrong in my code so that the save goes and then the OpenReport follows?

Private Sub cmdPrnFinal_Click()
On Error GoTo Err_cmdPrnFinal_Click

Dim stDocName, strWhere As String

If Me.Dirty = True Then
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
MsgBox "Record has been saved.", vbOKOnly, "Saved Record"
Else

stDocName = "rptWAFinREp"

If Not IsNull(Me.WAID) Then
strWhere = "WAID = " & Me.WAID

Else: Exit Sub

End If

DoCmd.OpenReport stDocName, acViewPreview, , strWhere

End If


Exit_cmdPrnFinal_Click:
Exit Sub

Err_cmdPrnFinal_Click:
MsgBox Err.Description
Resume Exit_cmdPrnFinal_Click

End Sub
 
You need to assign stdocname outside of the for else statement.


Ian Mayor (UK)
Program Error
Always make your words sweet and nice. Because you never know when you may have to eat them.
 
How are ya nastar1 . . .

. . . and this?
Code:
[blue]   Dim stDocName, strWhere As String

   If Me.Dirty Then
      DoCmd.RunCommand acCmdSaveRecord
      MsgBox "Record has been saved.", vbOKOnly, "Saved Record"
      stDocName = "rptWAFinREp"
      If Not IsNull(Me.WAID) Then strWhere = "WAID = " & Me.WAID
      DoCmd.OpenReport stDocName, acViewPreview, , strWhere
   End If[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997
Also faq181-2886
 
Thanks guys. Your solutions worked perfectly.

And I'm learning a little with every solution.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top