Results 1 to 4 of 4
  1. #1
    GregHolden is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Jun 2012
    Posts
    5

    Entering formula in text box

    I am attempting to enter a formula in a text box. The formula is a fairly long If...Then..Else statement (the formula is too long to use IIf.)

    I have entered (what I believe to be) a valid If..Then..Else statement by adding the text box and then building the event in the code builder.



    The problem I am having is that the text box continues to be Unbound. On the property sheet the [Event Procedure] is present in the "On Click" option. When I click on the the dot box, the Private Subroutine window shows the code.

    When I attempt to generate the report, the text box remains empty.

    I apologize if this is a dumb question - I am fairly new to Access - but how can I get Access to recognize and run the If Then Else statement each time the report is generated?

    Thank you for any assistance you can provide.

    Greg

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,636
    By 'code builder' do you mean VBA editor? The code would have to be a function procedure. The function could be behind the report or a general module. Then call the function from the textbox ControlSource. Post the code for analysis.
    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.

  3. #3
    GregHolden is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Jun 2012
    Posts
    5
    Thank you for looking at this June.
    This subroutine is looking at the values in a query to determine what type of a report was generated. I believe the If Then Else statement works fine (I have a similar statement in another place in the database, with no issues on execution) - but I just can't figure out how to have the text box check this statement when the report is generated.

    Greg

    Private Sub Report_type_formula__Click()
    If [Monthly Arrest Query]![TA Felony Report] = 1 Or [Monthly Arrest Query]![Non-TA Felony Report] = 1 Then
    [Report type] = "Felony"
    Else
    If [Monthly Arrest Query]![TA Misdemeanor Report] = 1 Or [Monthly Arrest Query]![Non-TA Misdemeanor Report] = 1 Or [Monthly Arrest Query]![TA Domestic A&B Report] = 1 Or [Monthly Arrest Query]![Non-TA Domestic A&B Report] = 1 Then
    [Report type] = "Misdemeanor"
    Else
    If [Monthly Arrest Query]![TA FR-300] = 1 Or [Monthly Arrest Query]![Non-TA FR-300] = 1 Then
    [Report type] = "FR-300"
    Else
    [Report type] = "Supplement"
    End If


    End Sub

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,636
    Cannot pull data from a table or query object like that. All those [Monthly Arrest Query] fields would have to be in the form or report RecordSource and then the table/query prefix is not needed unless the RecordSource has fields from different sources with identical name.

    Where is the button this click event is associated with - on report or form? What is [Report Type] - a field or just textbox name - and on form or report?

    For textbox on report cannot use code to reference the textbox and set its value. That is okay on a form but not report. A textbox on report can call a function and value returned by function will be the value in textbox. As an example, intrinsic Date() function will display the current date in textbox. So a user defined function can be called by textbox:
    = ReportType()

    Then example UDF (assuming all fields are in the report RecordSource):

    Function ReportType()
    If [TA Felony Report] = 1 Or [Non-TA Felony Report] = 1 Then
    ReportType = "Felony"
    ElseIf [TA Misdemeanor Report] = 1 Or [Non-TA Misdemeanor Report] = 1 Or [TA Domestic A&B Report] = 1 Or [Non-TA Domestic A&B Report] = 1 Then
    ReportType = "Misdemeanor"
    ElseIf [TA FR-300] = 1 Or [Non-TA FR-300] = 1 Then
    ReportType = "FR-300"
    Else
    ReportType = "Supplement"
    End If
    End Function

    Where is the similar code you say is successful and what does it do?

    BTW, recommend no spaces or special characters/punctuation (underscore is exception) in names.
    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.

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

Similar Threads

  1. IIF formula in an unbound text box using date()
    By probablyjoel in forum Forms
    Replies: 3
    Last Post: 04-20-2012, 12:03 PM
  2. Replies: 2
    Last Post: 09-25-2011, 08:52 AM
  3. formula in text box problem
    By kwooten in forum Reports
    Replies: 7
    Last Post: 09-12-2011, 08:19 AM
  4. Replies: 19
    Last Post: 03-31-2011, 09:22 AM
  5. Entering Text in Combo Form
    By Bobt in forum Forms
    Replies: 2
    Last Post: 10-22-2010, 03:53 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