Results 1 to 9 of 9
  1. #1
    EffenNewGuy is offline Novice
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Posts
    6

    Referencing unbound text box on report

    I have a data entry form with a command button to open a report form. I open the report using VB, and then I try to populate unbound text boxes on the report, I get no results. I'm thinking I need to requery the report form or something for these values to show up, but I can't use Requery...



    MSAccess 2007
    Windows Vista

    Here's the code:


    Public Sub PrintRpt_Click()
    On Error GoTo Error_Handler

    DoCmd.OpenReport "rpt_Calculation", acViewPreview

    Reports![rpt_Calculation]!rptRepeatKey = RepeatKey
    Reports![rpt_Calculation]!rptWorkflowKey = WorkflowKey
    Reports![rpt_Calculation]!rptUtilizationKey = UtilizationKey
    Reports![rpt_Calculation]!rptIBkey = IBKey
    Reports![rpt_Calculation]!rptBCkey = BCKey
    Reports![rpt_Calculation]!rptCustSel = TempVars("CustName").Value


    Exit_Procedure:
    Exit Sub
    Error_Handler:
    MsgBox "Error # " & Err.Number & vbCrLf & Err.Description, vbExclamation, "Application Error"
    Resume Exit_Procedure

    End Sub

    In debug, all the fields have correct values in them, but when I look at the report, they are all blank... All unbound text boxes in the form are named the same way as here - rptRepeatKey, etc...

    Please help. Thanks SO SO much!

  2. #2
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    You can't do it like that. You will have to have the text box on the report reference the form, not the other way around. So, one of the text boxes on the report would be:

    =[Forms]![YourFormNameHere]![RepeatKey]

    and then the next

    =[Forms]![YourFormNameHere]![WorkFlowKey]

    and so on.

  3. #3
    EffenNewGuy is offline Novice
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Posts
    6
    Hi, Bob! Thanks for the swift reply.

    These fields are variables within the program, and not resident on any form (at the moment...), so the form reference does not work for me. I tried that already...

  4. #4
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Quote Originally Posted by EffenNewGuy View Post
    Hi, Bob! Thanks for the swift reply.

    These fields are variables within the program, and not resident on any form (at the moment...), so the form reference does not work for me. I tried that already...
    You will need to then create a function for each so you can reference it:

    In a Standard Module:
    Code:
    Function GetRepeatKey() As String ' or a different type if numeric
    GetRepeatKey = RepeatKey
    End Function
    And then in the control source you can use

    =GetRepeatKey()

  5. #5
    EffenNewGuy is offline Novice
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Posts
    6
    Okay, I get it. Seems very indirect, but okay ... Thanks so much.

  6. #6
    EffenNewGuy is offline Novice
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Posts
    6
    Tried the functions ... no work-y. Now I get the "#name?" back on the report where I expect to have a value.

  7. #7
    boblarson is offline --------
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2011
    Posts
    1,272
    Quote Originally Posted by EffenNewGuy View Post
    Tried the functions ... no work-y. Now I get the "#name?" back on the report where I expect to have a value.
    Make sure that your text boxes do not have the same name as your field names. Also, did you remember to include the parens in the function call:

    =GetRepeatKey()

    And, make sure that the functions that pull the information back are in a STANDARD MODULE (not in a form, report or class module) and that the module name is not the same as any of the procedure names. The functions to return the values can't be on anything other than standard modules and that means that the variables also need to be within the same scope.

  8. #8
    EffenNewGuy is offline Novice
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Posts
    6
    Yes, all functions are Public and the control source reference in the property list includes the (). Now the report shows an empty field. Looks like when the function gets called, the variables get initialized... ?

    Alternative strategy - I added these fields to the main form as hidden fields and reference them like I do the non-hidden fields from that form (for the report), but now the report shows #Error. I'm progressing!! hahaha! I'll take a closer look at all my fields and spellings. Don't know what else to do. It seems VERY strange to me that this is so difficult.

    Thanks for all your help!

  9. #9
    EffenNewGuy is offline Novice
    Windows Vista Access 2007
    Join Date
    Jun 2011
    Posts
    6

    Smile

    The hidden fields worked (after syncing up field names)... although it seems like a very hokey way of doing this. I'll take working vs. non-working any day, though.

    thanks again!

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

Similar Threads

  1. Using Dlookup in unbound text box in report
    By PrintShopSup in forum Reports
    Replies: 3
    Last Post: 12-27-2010, 10:29 AM
  2. Input data In unbound text box
    By chu3w in forum Forms
    Replies: 1
    Last Post: 04-01-2010, 10:21 AM
  3. Unbound Text box in reports
    By Overdive in forum Reports
    Replies: 1
    Last Post: 02-17-2010, 09:52 AM
  4. Transfer Text to Unbound Form
    By DWS in forum Forms
    Replies: 3
    Last Post: 08-25-2009, 08:04 AM
  5. Unbound text box truncating text
    By gddrew in forum Forms
    Replies: 0
    Last Post: 03-02-2006, 11:26 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