Print Report from Combo Box Selection

  • Thread starter Thread starter depawl
  • Start date Start date
D

depawl

In this instance I'm trying to have the user select an Organization Code
from a combo box in a form and then click on a command button to print a
report of details for the selected orgcode from the combo box. It seemed
like it was working for a while but now it is stuck on one record, no
matter what the user selects. Also, it frequently gives the following
error: "Update or CancelUpdate without AddNew or Edit"
The code I have is:

Private Sub OrgCodecombo_AfterUpdate()
Me.RecordsetClone.Findfirst "[ORGCODE] = '" & Me![OrgCodecombo] & "'"
Me.Bookmark = Me.RecordsetClone.Bookmark
End Sub

Private Sub CommandOrgCode_Click()
Dim strDocName As String
Dim strWhere As String
strDocName = "OrgCodeReport"
strWhere = "[ORGCODE] = '" & Me![OrgCodecbo] & "'"
DoCmd.OpenReport strDocName, acPreview, , strWhere
Exit_CommandOrgCode_Click:
Exit Sub
End Sub

Seems like maybe I need a requery or something but I can't seem to get it.
Thanks.
 
I see a couple of possible things.

1) If you were using Me.Recordset.Clone, I would say this is a definite
problem, but I'm not sure with Me.RecordsetClone. The first one will create
a new copy each time it is used. If the second one does also, then you are
referring to two different recordsets in the lines
Me.RecordsetClone.Findfirst "[ORGCODE] = '" & Me![OrgCodecombo] & "'"
Me.Bookmark = Me.RecordsetClone.Bookmark

To get around this, assign the clone to a recordset variable.

Example:
Dim rst As DAO.Recordset
Set rst = Me.RecordsetClone
rst.Findfirst "[ORGCODE] = '" & Me![OrgCodecombo] & "'"
Me.Bookmark = rst.Bookmark
Set rst = Nothing

The other thing I see is that in one place you have "[OrgCodecombo]" and in
another you have "[OrgCodecbo]", could this be a typo causing you a problem?
Also, you are using single quotes in the strWhere clause. Is the value a
string value? Do any of the possible selection values have apostrophes in
them (i.e. O'Hare)?

--
Wayne Morgan
Microsoft Access MVP


depawl said:
In this instance I'm trying to have the user select an Organization Code
from a combo box in a form and then click on a command button to print a
report of details for the selected orgcode from the combo box. It seemed
like it was working for a while but now it is stuck on one record, no
matter what the user selects. Also, it frequently gives the following
error: "Update or CancelUpdate without AddNew or Edit"
The code I have is:

Private Sub OrgCodecombo_AfterUpdate()
Me.RecordsetClone.Findfirst "[ORGCODE] = '" & Me![OrgCodecombo] & "'"
Me.Bookmark = Me.RecordsetClone.Bookmark
End Sub

Private Sub CommandOrgCode_Click()
Dim strDocName As String
Dim strWhere As String
strDocName = "OrgCodeReport"
strWhere = "[ORGCODE] = '" & Me![OrgCodecbo] & "'"
DoCmd.OpenReport strDocName, acPreview, , strWhere
Exit_CommandOrgCode_Click:
Exit Sub
End Sub

Seems like maybe I need a requery or something but I can't seem to get it.
Thanks.
 
Back
Top