Results 1 to 4 of 4
  1. #1
    Akchayan is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Aug 2022
    Posts
    102

    Change the value of a text field with an If Clause.

    Hello everyone,




    I have this code here:
    If IsNull(Forms!foPayroll!ExpenseText) Then
    Me!ExpenseText.Visible = False
    Else
    Me!ExpenseText.Visible = True
    End If

    If IsNull(Forms!foPayroll!ExpenseAmount) Then
    Me!Expenses.Visible = False
    Else
    Me!Expenses.Visible = True
    End If


    But I want that when this if clause is enforced not the visibility is changed but that another value becomes visible.


    Thanks for the help!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    hide the boxes in 1 sub, then call the sub when needed:


    Code:
    sub Form_Load()
       EnableMyBoxes
    end if
    
    
    sub Expenses_AfterUpdate()
       EnableMyBoxes
    end sub
    
    
    sub EnableMyBoxes()
      Me!ExpenseText.Visible = not IsNull(Forms!foPayroll!ExpenseText)
      Me!Expenses.Visible = not IsNull(Forms!foPayroll!ExpenseAmount) 
    end sub

  3. #3
    Akchayan is offline Competent Performer
    Windows 7 64bit Access 2016
    Join Date
    Aug 2022
    Posts
    102
    Is there no way to rewrite my If clause?
    If IsNull(Forms!foPayroll!ExpenseText) Then
    Me!ExpenseText.Visible = False
    End If

    I just want to display a specified text when the If clause here applies. So a text like "Expenses".


    Is there a way to do this?

  4. #4
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    Maybe
    Me.Expenses = Nz(Forms!foPayroll.ExpenseAmount,0)
    where 0 is your "other amount". The IF blocks are probably not needed at all.

    EDIT -possibly a string is needed, not zero.
    Me.Expenses = Nz(Forms!foPayroll.ExpenseAmount,"my string")
    Last edited by Micron; 09-09-2022 at 01:50 PM. Reason: added comment
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 5
    Last Post: 09-03-2020, 11:49 AM
  2. Replies: 7
    Last Post: 07-01-2017, 01:07 AM
  3. how to change text field size from 20 to 26
    By Azariah in forum Database Design
    Replies: 4
    Last Post: 07-02-2015, 09:15 AM
  4. Replies: 3
    Last Post: 02-28-2015, 06:52 PM
  5. Change Text field to Memo Field in a Query
    By Yarbz in forum Queries
    Replies: 5
    Last Post: 06-28-2012, 05:24 PM

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