Results 1 to 5 of 5
  1. #1
    newbieX is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jul 2013
    Posts
    111

    Programmatically altered label not recognized in if statement

    On main menu form (MainForm), when user clicks a button it runs the following code, which opens a new form and changes the title(caption)- (displayed in a label in the header section).

    Code:
    DoCmd.OpenForm "Validate", acNormal
    Forms!Validate.Lbl_BannerValidate.Caption = "Edit Data"
    When the form opens, I want to check to see what the title is, and depending on the title, perform an action. The form opens and displays the correct title after running the above code ("Edit Data"), however, it is not recognizing the caption value correctly. Even though the caption correctly displays the programmatically altered caption, the below code only recognizes the default caption listed in the label's (Lbl_BannerValidate) property box.



    Code:
    Private Sub Form_Open(Cancel As Integer)
        DoCmd.Close acForm, "MainForm", acSaveNo
    
        If Me!Lbl_BannerValidate.Caption = "Validate Data" Then
            If Me!cmdSamples.Visible = "No" Then
                 Me!cmdSamples.Visible = "Yes"
            End If
        End If
        If Me!Lbl_BannerValidate.Caption = "Edit Data" Then
            If Me!cmdSamples.Visible = "Yes" Then
                Me!cmdSamples.Visible = "No"
            End If
        End If
    
        Debug.Print Me!Lbl_BannerValidate.Caption
    End Sub
    Debug.Print returns the value "Validate Data" instead of "Edit Data".

    How can I rewrite my code to recognize the new caption and execute the proper if statements when true?

    Access 2007

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Does
    Forms!Validate!Lbl_BannerValidate.Caption = "Edit Data"

    make a difference?

    forms!Validate ! not period

  3. #3
    newbieX is offline Competent Performer
    Windows 7 64bit Access 2007
    Join Date
    Jul 2013
    Posts
    111
    No. Doesn't make a bit of difference.I did notice that when using Debug print statement in MainForm coding, the correct value is returned. Do I need to pass this value to the form that is being opened? If so, how?

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Information can be passed to a form with OpenArgs argument.

    DoCmd.OpenForm "Validate", acNormal, , , , , "Edit Data"

    Then refer to OpenArgs

    If Me.OpenArgs = "Validate Data" Then
    Last edited by June7; 09-16-2014 at 04:02 PM.
    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.

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You have to look at when things happen.

    1) Main form -> command -> DoCmd.OpenForm "Validate", acNormal

    2) Form "Validate" opens
    Form "Validate" Form_Open code executes -> caption is "Validate Data"
    Form "Validate" Form_Open code completes

    3) Now back to Main form -> command -> Forms!Validate.Lbl_BannerValidate.Caption = "Edit Data"

    4) Form "Validate" Lbl_BannerValidate.Caption is now "Edit Data" ... but no code executes to set the button states.

    I would use the OpenArgs argument as June suggests...

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

Similar Threads

  1. Field Not Recognized
    By Rustin788 in forum Reports
    Replies: 1
    Last Post: 08-25-2014, 10:34 AM
  2. Using a Default Date that can be altered.
    By bundymick in forum Access
    Replies: 3
    Last Post: 02-11-2014, 07:56 AM
  3. Combo box is recognized as digit format
    By Gealeks in forum Forms
    Replies: 8
    Last Post: 11-27-2013, 03:08 PM
  4. Loop or Array not recognized
    By dvgef2 in forum Forms
    Replies: 6
    Last Post: 05-31-2013, 08:37 AM
  5. New Record not recognized in my queries
    By Kimmcdt in forum Queries
    Replies: 6
    Last Post: 01-16-2010, 10:26 PM

Tags for this Thread

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