Results 1 to 4 of 4
  1. #1
    Brigsy29591 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2015
    Posts
    2

    Macro to Change label before opening Form

    I am working on a code that will run a few queries then display the results in a form.

    I need to be able to change the text contained within a label before the form is opened.
    For example I allow the User to select a date banding in the Welcome form and then run the code.
    I want the next form to open up with the Title "......Weeks..." if they selected the weeks Banding or ".....Months.." id they selected the Months banding.

    My Current code looks like this:

    Public Sub Run_Query_Click()
    On Error GoTo Err_Run_Query_Click
    DoCmd.SetWarnings False
    Dim stDocName As String

    stDocName = "Set_Dates"
    DoCmd.OpenQuery stDocName, acNormal, acEdit


    Call create_sql

    DoCmd.RunSQL Final_sql
    DoCmd.RunSQL query2


    Exit_Run_Query_Click:
    DoCmd.SetWarnings False
    DoCmd.Close acQuery, "Set_Dates", acSaveYes
    DoCmd.Close acQuery, "Menu", acSaveYes
    stDocName = "03Campaigns"

    DoCmd.OpenForm stDocName, , , stLinkCriteria



    Exit Sub
    Err_Run_Query_Click:
    MsgBox Err.Description
    Resume Exit_Run_Query_Click

    End Sub




    This is contained within the Menu Form and calls into a Module.

    The label I wish to change is in the Form [03Campaigns] and is called "Label23".

    I've tried a few options such as the caption extension but it doesn't seem to work.

    Does anyone have any ideas?

    Many thanks

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Immediately after the OpenForm try

    Forms!03Campaigns.Label23.Caption = "Whatever"

    You could also use OpenArgs and have code in the second form's open event.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Brigsy29591 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Sep 2015
    Posts
    2
    That worked perfectly, I'd used that command in different sections but it failed. I guess placement was the key.

    Thanks for your help.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No problem, and welcome to the site by the way!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Change Label on Form
    By jmitchelldueck in forum Programming
    Replies: 2
    Last Post: 08-24-2015, 07:28 AM
  2. Replies: 4
    Last Post: 05-23-2014, 09:51 AM
  3. Replies: 3
    Last Post: 02-20-2014, 02:00 PM
  4. Replies: 9
    Last Post: 02-04-2013, 03:22 PM
  5. Change size of Label
    By amerifax in forum Access
    Replies: 1
    Last Post: 10-17-2012, 06:18 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