Results 1 to 6 of 6

Make unbound Object Frame visible based on VBA

  1. #1
    JoeJr is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2019
    Posts
    40

    Make unbound Object Frame visible based on VBA


    Hello all,

    Question/issue:

    I have a form that has three unbound object frames that house pictures. Currently I have visible set to no in Property sheet. What I want them to do is display based on a field value. below is what I am looking for.

    If field value is between 23-31 then unbound object 1 = true (visible)
    If field value is between 32-35 then unbound object 2 = true(visible)
    If field value is between 36-40 then unbound object 3 = true(visible)

    what would the VBA code look like for that? I am correct by making the property sheet not visible for each unbound object frame?

    Thank you for your help

  2. #2
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    2,040
    Couple of questions as to how to code and where to put code:
    Do you want only one to be visible at a time?
    Does the user change the field value while the form is being displayed and you want the code to change the visible property accordingly?
    If the field value already exists in a bound control, do you want the corresponding object frame to be visible as the user scrolls thru the records?

  3. #3
    JoeJr is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2019
    Posts
    40
    Quote Originally Posted by davegri View Post
    Couple of questions as to how to code and where to put code:
    Do you want only one to be visible at a time?
    Does the user change the field value while the form is being displayed and you want the code to change the visible property accordingly?
    If the field value already exists in a bound control, do you want the corresponding object frame to be visible as the user scrolls thru the records?

    Thank you so much for the response. Yes I only want one to display at a time. When the user updates the number within the field on that record set, the object will diplay based on the value. Yes As the user scrolls thru the records, I would like the corresponding object to be viewed.

  4. #4
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    2,040
    All below is air code, off the top of my head. You need to substitute your object names.

    OK. To make the correct object show when scrolling, we need to use the form_current event.
    Code:
    Private sub Form_Current()
        Object1.visible = false
        Object2.visible = false
        Object3.visible = false
        Select Case nz(FieldValue)
            Case 23 to 31
                Object1.visible = true
            Case 32 to 35
                Object2.visible = true
            Case 36 to 40
                Object3.visible = true
            Case else
                msgbox "Unknown FieldValue"
        End Select
    End Sub
    When the user updates the FieldValue field

    Code:
    Private sub FieldValue_AfterUpdate
        If Not isnull(FieldValue) then    
            Call Form_Current
        End If
    End Sub

  5. #5
    JoeJr is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2019
    Posts
    40
    Quote Originally Posted by davegri View Post
    All below is air code, off the top of my head. You need to substitute your object names.

    OK. To make the correct object show when scrolling, we need to use the form_current event.
    Code:
    Private sub Form_Current()
        Object1.visible = false
        Object2.visible = false
        Object3.visible = false
        Select Case nz(FieldValue)
            Case 23 to 31
                Object1.visible = true
            Case 32 to 35
                Object2.visible = true
            Case 36 to 40
                Object3.visible = true
            Case else
                msgbox "Unknown FieldValue"
        End Select
    End Sub
    When the user updates the FieldValue field

    Code:
    Private sub FieldValue_AfterUpdate
        If Not isnull(FieldValue) then    
            Call Form_Current
        End If
    End Sub
    Awesome!! worked like a charm! I see what I was doing wrong on the case calls. Thanks for the help

  6. #6
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    2,040
    Glad to help. Good luck with the project.

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

Similar Threads

  1. different unbound object frame per record
    By accrep18 in forum Reports
    Replies: 8
    Last Post: 03-20-2018, 02:14 PM
  2. Unbound Object Frame Shrinks Data When Edited
    By Squirrel1804 in forum Access
    Replies: 6
    Last Post: 11-05-2015, 05:53 PM
  3. Unbound Object Frame Not Updating
    By MrSpadMan in forum Reports
    Replies: 7
    Last Post: 02-06-2013, 06:30 PM
  4. Unbound Object Frame
    By wsm_al in forum Access
    Replies: 1
    Last Post: 12-02-2011, 05:40 PM
  5. Replies: 1
    Last Post: 08-05-2010, 12:11 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
  •  
Tech Forums: Microsoft Office Forums