+ Reply to Thread
Results 1 to 5 of 5

Run code each time form is opened

Hybrid View

  1. #1
    Registered User
    Join Date
    06-26-2014
    Location
    Boston, MA
    MS-Off Ver
    Office 365
    Posts
    11

    Run code each time form is opened

    Hey everyone,
    The problem i'm need help on is that I have a every time this form opens (ResourceForm) I need the following code to run to flip the checkbox value. This works when adding the code to a button but not for when the form loads. I feel like there's something incredibly simple that i'm missing and initialize doesn't seem to be the answer as i'll be opening this form many times. Any help would be greatly appreciated!

    User flow:
    If the selected text appears in the cell when the form is opened the corresponding checkbox will be true.


    Public Sub ResourceForm_Activate() 
        Dim celltxt As String
        celltxt = ActiveSheet.Range("E9").Value
        If InStr(celltxt, "SSS1B", vbTextCompare) Then
            CheckBox1.Value = True
        Else
            CheckBox1.Value = False
        End If
    End Sub
    InsertResource_Test.xlsm
    Last edited by brandonboucher; 07-01-2014 at 01:28 PM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,645

    Re: Run code each time form is opened

    It should be UserForm_Activate, not formname_Activate.
    Public Sub UserForm_Activate() 
    Dim celltxt As String
    
        celltxt = ActiveSheet.Range("E9").Value
    
        If InStr(celltxt, "SSS1B") Then
              CheckBox1.Value = True
        Else
            CheckBox1.Value = False
        End If
        
    End Sub
    Last edited by Norie; 07-01-2014 at 11:17 AM.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor pareshj's Avatar
    Join Date
    05-20-2014
    Location
    MUMBAI
    MS-Off Ver
    2007 & 2010
    Posts
    447

    Re: Run code each time form is opened

    Hi brandonboucher,

    Check the attached file and hope this will help you.

    InsertResource_Test.xlsm


    Regards,
    Paresh J
    Click on "* Add Reputation" as a way to say thanks

  4. #4
    Registered User
    Join Date
    06-26-2014
    Location
    Boston, MA
    MS-Off Ver
    Office 365
    Posts
    11

    Re: Run code each time form is opened

    @Nori and @Pareshj - Thank you both! Looks like the same response to both and that fixed it.

  5. #5
    Forum Contributor pareshj's Avatar
    Join Date
    05-20-2014
    Location
    MUMBAI
    MS-Off Ver
    2007 & 2010
    Posts
    447

    Re: Run code each time form is opened

    Please mark this thread as SOLVED and click * Add reputation as way to say thanks..

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to set a Global Macros so that it gets opened every time an excel file is opened?
    By pericopericone in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-09-2013, 05:53 AM
  2. [SOLVED] VBA Code open files in folder, copy text to workbook-Next time folder opened copy only new
    By Bikeman in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-02-2013, 07:59 PM
  3. Loading a user form crashes Excel 2003 -- the second time it's opened
    By Bob Eaton in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-23-2012, 07:19 PM
  4. Access - run code once form is opened
    By adgjqetuo in forum Access Programming / VBA / Macros
    Replies: 3
    Last Post: 12-07-2010, 02:54 AM
  5. [SOLVED] how can I make a form number change everytime the form is opened
    By babydumplingspita in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-10-2005, 03:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1