I can't beleive it!!

  • Thread starter Thread starter derek
  • Start date Start date
D

derek

Hi, Help

I have a form that has a print button that prints details
from the form. It works great when I print an existing
record but when I enter a new record and press print I get
an error as if the record is not yet saved or dirty. I
placed a Requery button on the form, even this does not
work. On occation even when I close the form and reopen
it and go to the new record it still will not show on the
print preview, all I get is error message.

What I can not beleive is that after 8 years working with
access is that no one has ever shown me a reliable
solution to this problem. What am I missing!!

Thanks
 
Assuming your form has a numeric field named "ID" that uniquely identifies
the record:

Private Sub cmdPrint_Click()
Dim strWhere As String

If Me.Dirty Then
Me.Dirty = False
End If
If Me.NewRecord Then
MsgBox "Select a record to print"
Else
strWhere = "[ID] = " & Me.ID
DoCmd.OpenReport "MyReport", acViewPreview, , strWhere
End If
End Sub
 
It likely that your Report gets the data from the Table, not the Form. If
the Record is not yet saved / updated into the Table, you need to do so
before trying to print your Report.

You can place the following code just before your DoCmd.OpenReport statement
to save your Record or the Report.

....
DoCmd.RunCommand acCmdSaveRecord
DbEngine.Idle dbRefreshCache
DoEvents

DoCmd.OpenReport ...
 
Hi and thanks.

When I try your code iget "Variable not defined" at
dbRefreshCache

Am I missing something?
 
Hi and Thanks

When I try your code I get compile error message "method
or Data member not found"

Any clues?

Thanks
-----Original Message-----
Assuming your form has a numeric field named "ID" that uniquely identifies
the record:

Private Sub cmdPrint_Click()
Dim strWhere As String

If Me.Dirty Then
Me.Dirty = False
End If
If Me.NewRecord Then
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.

Reply to group, rather than allenbrowne at mvps dot org.

Hi, Help

I have a form that has a print button that prints details
from the form. It works great when I print an existing
record but when I enter a new record and press print I get
an error as if the record is not yet saved or dirty. I
placed a Requery button on the form, even this does not
work. On occation even when I close the form and reopen
it and go to the new record it still will not show on the
print preview, all I get is error message.

What I can not beleive is that after 8 years working with
access is that no one has ever shown me a reliable
solution to this problem. What am I missing!!

Thanks


.
 
This is a bound form?

Check your references:
http://members.iinet.net.au/~allenbrowne/ser-38.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

derek said:
Hi and Thanks

When I try your code I get compile error message "method
or Data member not found"

Any clues?

Thanks
-----Original Message-----
Assuming your form has a numeric field named "ID" that uniquely identifies
the record:

Private Sub cmdPrint_Click()
Dim strWhere As String

If Me.Dirty Then
Me.Dirty = False
End If
If Me.NewRecord Then
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.

Reply to group, rather than allenbrowne at mvps dot org.

Hi, Help

I have a form that has a print button that prints details
from the form. It works great when I print an existing
record but when I enter a new record and press print I get
an error as if the record is not yet saved or dirty. I
placed a Requery button on the form, even this does not
work. On occation even when I close the form and reopen
it and go to the new record it still will not show on the
print preview, all I get is error message.

What I can not beleive is that after 8 years working with
access is that no one has ever shown me a reliable
solution to this problem. What am I missing!!

Thanks


.
 
Hi

Yes

Thank you./
-----Original Message-----
This is a bound form?

Check your references:
http://members.iinet.net.au/~allenbrowne/ser-38.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Hi and Thanks

When I try your code I get compile error message "method
or Data member not found"

Any clues?

Thanks
-----Original Message-----
Assuming your form has a numeric field named "ID" that uniquely identifies
the record:

Private Sub cmdPrint_Click()
Dim strWhere As String

If Me.Dirty Then
Me.Dirty = False
End If
If Me.NewRecord Then
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.

Reply to group, rather than allenbrowne at mvps dot org.

Hi, Help

I have a form that has a print button that prints details
from the form. It works great when I print an existing
record but when I enter a new record and press print I get
an error as if the record is not yet saved or dirty. I
placed a Requery button on the form, even this does not
work. On occation even when I close the form and reopen
it and go to the new record it still will not show on the
print preview, all I get is error message.

What I can not beleive is that after 8 years working with
access is that no one has ever shown me a reliable
solution to this problem. What am I missing!!

Thanks


.


.
 
Thanks again Van

I have no idea what adding Microsoft DAO does but it
stopped the compile error. Unfortunateley it does not
solve the problem.

To make it simple I did not mention that the print button
is on a suform and it is information from the subform
which is not printing and shows error. So I created a
sample form with just the data from the main table, put a
print command button on the form with your code;

DoCmd.RunCommand acCmdSaveRecord
DbEngine.Idle dbRefreshCache
DoEvents

entered a new record pressed print and it works great. So
why do i still have problems when the same proceedure is
used on a subform?
 
The Subform is important!

It sounds to me that you are opening the Report with the RecordSource is a
parametrised Query or you use the WhereCondition argument of the OpenReport
Method. Either case, you use the reference to a Control on the Subform as
the Parameter or in the WhereCondition. The likely problem is that you have
the incorrect syntax to reference the Control.

If that is the case, try the full reference to the Control with the syntax
like:

Forms!MainFormName!SuformCONTROLName.Form!ControlName

Note that the SubformCONTROLName may be different from the name of the Form
being used as the Subform (more accurately, being used as the SourceObject
of the SubformCONTROL). You will need to check the SubformCONTROLName in
the DesignView of the Main Form.
 
Hi Van

Very intuitive!!.

I did something that I never normally do. I always
reference main and subforms on an auto number field. On
this occasion trying to save time I used a time and date
field that is updated by an after update procedure in the
main text field. Sometimes however data in the main text
field is entered programmatically and of course this does
not update the date time field. And this caused the error.

So I then added an auto number field to the subforms
underlying table and using the expression builder in the
criteria box of the underlying query, located the subform
and the field containing the auto number . I did not
realise that when the forms are not loaded that when you
select the subform in the expression builder it references
directly to the subform without referencing the main
form. Again causing an error. Although this was not be
cause of my original problem it did make an error when I
tried it. I corrected the problem as you suggested and now
for the first time in eight years I have up to the second
information and no print problems. The original heading
for this query was "I can't believe it" I have never seen
or read this solution in a book and never Previously had
this problem satisfactorily answered in any user group.

Once again my thanks.
 
Back
Top