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!

Subreport has no data, but still want to show labels and text fields

Status
Not open for further replies.

handsrfull

Technical User
Feb 22, 2008
8
US
Is there a way to show a subreport even if there is no data in it? I still need the fields to show on my report.
 
I do this by creating a blank record with a populated dummy field that doesn't print on the report. I think I remember seeing dhookum post something about putting "= 1" in the sorting/grouping box, and using the group header as the report header, but can't remember exactly. He maintains a website at that may have some tips, or search past posts & FAQs.

"Before you criticize someone, you should walk a mile in their shoes.
That way, when you criticize them, you're a mile away and you have their shoes."
 
I need help with the following code. What I want to do is export the data from a access form to a word document. If all fields in the access form have data in them, then it will fill the word document completely. However, if the code see's one field in access with no data, then it will stop at that field in the word document. How can I export the data and skip the blank field?

Below is my code.

Private Sub cmdExportToWord_Click()
On Error GoTo cmdExportToWord_Err

Dim objWord As Word.Application

'Start Microsoft Word 97.
Set objWord = CreateObject("Word.Application")

With objWord
'Make the application visible.
.Visible = True

'Open the document.
.Documents.Open ("C:\Path\Docname.doc")

'Move to each bookmark and insert text from the form.
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
.ActiveDocument.Bookmarks("XYZ").Select
.Selection.Text = (CStr(Forms!frmXYZ!txtXYZ))
End With

'Save File with new name
objWord.ActiveDocument.SaveAs InputBox("Save As what file name? This file will save" & _
" under your My Documents folder:", "Save File")

cmdExportToWord_Err:
'If a field on the form is empty, remove the bookmark text, and
'continue.
If Err.Number = 94 Then
objWord.Selection.Text = ""
End If

End Sub
 
Might wanna start a new thread for this, since it isn't exactly about what the subject line states.

"Business conventions are important because they demonstrate how many people a company can operate without."
 
I don't add a "dummy" record. I would add some text boxes behind the subreport that would display if the subreport was blank.

Regarding your OT question, your error handler doesn't resume next. I think you wouldn't generate an error if your code was like:
Code:
        .ActiveDocument.Bookmarks("XYZ").Select
        .Selection.Text = Forms!frmXYZ!txtXYZ & ""

Duane MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top