A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Please help this code to work



 
 
Thread Tools Display Modes
  #1  
Old December 22nd, 2006, 06:35 AM posted to microsoft.public.access.forms
JustMe
external usenet poster
 
Posts: 96
Default Please help this code to work

Following an example on another post (I believe by Allen), I put a button on
my form which prints out a report of the current record.

frmOrderStatus contains fields from table tFits and also contains 3
subreports:

On Tab1:
1. sfmCommentLatest - linked on Style_pk & Style_fk
-displays latest comment from tComments table, according to timestamp

2. sfmOSOrders - linked on Style_pk & Style_fk, located on tab1
-displays many fields queried from table tOrders

On Tab2:

3. sfmCommentsHistory - linked on Style_pk & Style_fk, located on tab2
-displays all comments from tComments table for the current style on
Parent form



I made a report layout called "rptStyleOSSummary" to print out all the same
info as on the first tab.


I placed a button on my parent form, "frmOrderStatus", with following click
event.

Private Sub btnPrintRecMain_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 = "[Style_pk] = """ & Me.[Style_pk] & """"
DoCmd.OpenReport "rptStyleOSSummary", acViewPreview, , strWhere
End If
End Sub




This works perfectly, bringing up the report, displaying all the info for
the current record. ...EXCEPT when there is no comment in the comments table
for that style. Then, the report is called up with no style in the linked
field, and errors all around in the other fields.

Help?

Thank you.
  #2  
Old December 22nd, 2006, 06:54 AM posted to microsoft.public.access.forms
Allen Browne
external usenet poster
 
Posts: 11,706
Default Please help this code to work

Sounds like the RecordSource of this report is a query that contains more
than one table?

If so, you need to use an outer join. In the upper pane of query design,
double-click the line joining the 2 tables. Access offers a dialog with 3
choices. Choose the 2nd or 3rd one (depending what you want.)

Note that you will have to be clear about critiera you apply to the table on
the outer side of the join also.

For an explanation of both issues, see:
The Query Lost My Records! (Nulls)
at:
http://allenbrowne.com/casu-02.html

--
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.

"justme" wrote in message
...
Following an example on another post (I believe by Allen), I put a button
on
my form which prints out a report of the current record.

frmOrderStatus contains fields from table tFits and also contains 3
subreports:

On Tab1:
1. sfmCommentLatest - linked on Style_pk & Style_fk
-displays latest comment from tComments table, according to timestamp

2. sfmOSOrders - linked on Style_pk & Style_fk, located on tab1
-displays many fields queried from table tOrders

On Tab2:

3. sfmCommentsHistory - linked on Style_pk & Style_fk, located on tab2
-displays all comments from tComments table for the current style on
Parent form



I made a report layout called "rptStyleOSSummary" to print out all the
same
info as on the first tab.


I placed a button on my parent form, "frmOrderStatus", with following
click
event.

Private Sub btnPrintRecMain_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 = "[Style_pk] = """ & Me.[Style_pk] & """"
DoCmd.OpenReport "rptStyleOSSummary", acViewPreview, , strWhere
End If
End Sub




This works perfectly, bringing up the report, displaying all the info for
the current record. ...EXCEPT when there is no comment in the comments
table
for that style. Then, the report is called up with no style in the linked
field, and errors all around in the other fields.

Help?

Thank you.



  #3  
Old December 22nd, 2006, 06:56 AM posted to microsoft.public.access.forms
Steve Schapel
external usenet poster
 
Posts: 1,422
Default Please help this code to work

Justme,

It sounds like the problem lies with the query that the report is based
on. In that query, the join between the main table and the Comments
table probably should be a Left join, whereas it sounds at the moment
you have an Inner Join. In design view of the query, double-click the
join line to the Comments table, and then select the option that
describes all main records and only matching comments.

--
Steve Schapel, Microsoft Access MVP

justme wrote:
Following an example on another post (I believe by Allen), I put a button on
my form which prints out a report of the current record.

frmOrderStatus contains fields from table tFits and also contains 3
subreports:

On Tab1:
1. sfmCommentLatest - linked on Style_pk & Style_fk
-displays latest comment from tComments table, according to timestamp

2. sfmOSOrders - linked on Style_pk & Style_fk, located on tab1
-displays many fields queried from table tOrders

On Tab2:

3. sfmCommentsHistory - linked on Style_pk & Style_fk, located on tab2
-displays all comments from tComments table for the current style on
Parent form



I made a report layout called "rptStyleOSSummary" to print out all the same
info as on the first tab.


I placed a button on my parent form, "frmOrderStatus", with following click
event.

Private Sub btnPrintRecMain_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 = "[Style_pk] = """ & Me.[Style_pk] & """"
DoCmd.OpenReport "rptStyleOSSummary", acViewPreview, , strWhere
End If
End Sub




This works perfectly, bringing up the report, displaying all the info for
the current record. ...EXCEPT when there is no comment in the comments table
for that style. Then, the report is called up with no style in the linked
field, and errors all around in the other fields.

Help?

Thank you.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:22 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.