Results 1 to 6 of 6
  1. #1
    XenoZephyr is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    16

    Question Unbound field prints ok if I use print preview but does not print if I try to print directly

    Hi,

    I am using the following code to print a letter based off a current record on a form:

    strReportName = "Candidacy"
    strCriteria = "[DatabaseID]=" & Me![DatabaseID]
    MsgBox "Load 1 sheet of Official Letterhead, then OK to continue"
    DoCmd.OpenReport strReportName, acViewPreview, , strCriteria

    That brings up the print preview and we can print that off. However, we want to print directly and not use that step and would like to just print with

    DoCmd.OpenReport strReportName, , , strCriteria

    When I do that though, the field that I created to format their address does not print at all. It is an unbound field. I will display the code before but it appears that the unbound field is the problem. All other fields are printed.


    On the report, I have hidden fields that include city, state, zip, etc and then an unbound field that puts them together with the proper formatting. It also has an if statement that checks to see if it should use the permanent address fields or the current address fields. When I use the print preview option, it works fine, but it's blank if I try to print directly.

    Any suggests to fix this would be greatly appreciated! Thanks!



    -----this is my Report_Load subroutine on the report in question

    Private Sub Report_Load()
    If [SameAsPerm] Then
    Add1 = [Permanent Address 1]
    If IsNull([Permanent Address 2]) Or [Permanent Address 2] = "" Then
    NeedAdd2 = False
    Else
    NeedAdd2 = True
    Add2 = [Permanent Address 2]
    End If
    City = [Permanent City]
    State = [Permanent State]
    Zip = [Permanent Zip]
    Country = [Permanent Country]
    If Country = "USA" Or Country = "US" Then
    NeedToSetCountry = False
    Else
    NeedToSetCountry = True
    End If
    Else
    Add1 = [Current Address 1]
    If IsNull([Current Address 2]) Or [Current Address 2] = "" Then
    NeedAdd2 = False
    Else
    NeedAdd2 = True
    Add2 = [Current Address 2]
    End If
    City = [Current City]
    State = [Current State]


    Zip = [Current Zip]
    NeedToSetCountry = False
    End If

    FullAddress = Add1
    If NeedAdd2 Then
    FullAddress = FullAddress & vbCrLf & Add2
    End If
    FullAddress = FullAddress & vbCrLf & City & ", " & State & " " & Zip
    If NeedToSetCountry Then
    FullAddress = FullAddress & vbCrLf & Country
    End If
    txtAddress = FullAddress

    End Sub

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    2,937
    Have you tried the code in the On Format event.
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    50,070
    I wonder if this can all be accomplished with IIf() expressions in textbox ControlSource or even in form RecordSource query.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    XenoZephyr is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    16
    Does Access 2010 have an On Format event? When I choose Report, there isn't a On Format or Format listed. Can I just write it as a subroutine and it works? If so, is it "Report_OnFormat"?

    I originally tried to do the IIF statement because someone told me that was better code to do it that way but I'm too novice to get to work. For example, I have multiple things to do in the "truepart" and I can't figure out how to get them all to work, it seems to only do one thing. Any suggestions on either method would be greatly appreciated!

    Thanks

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    50,070
    The Report does not have Format event, its parts do. Click on any header/footer or the detail section and you will see OnFormat event property.

    I just realized this code is attempting to set the Value property of a control on report and I don't think that can be done. However, a control can call a function that will return a value. So instead of a Format event, make this a Function procedure.

    Function FullAddress()
    ...
    'txtAddress = FullAddress 'comment or remove this line from the code
    End Function

    Then from txtAddress, call the function:
    =FullAddress()

    Added benefit is the code will run even in ReportView. The Format events only trigger for PrintPreview or direct to printer.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    XenoZephyr is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2012
    Posts
    16
    Awesome, thank you! I put it as a function and it works great now! Thanks, works and I feel like I understand more now too haha.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 03-01-2014, 07:07 AM
  2. Print & Print Preview Differ
    By IDH in forum Reports
    Replies: 3
    Last Post: 07-25-2012, 09:50 AM
  3. Replies: 1
    Last Post: 01-23-2011, 09:21 AM
  4. Print Preview different from Print Hardcopy
    By peterc in forum Reports
    Replies: 4
    Last Post: 10-27-2009, 05:35 AM
  5. Error when trying to print or print preview
    By TriAdX in forum Reports
    Replies: 8
    Last Post: 08-25-2009, 08:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums - Senior Forums