Results 1 to 8 of 8
  1. #1
    stu_C is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Mar 2010
    Posts
    38

    Change Lable text my macro

    Hi all
    Strange one for you, I need to have a button macro that when clicked brings up a dialoge box and you type in a date, once clicked ok changes the lable text on the report is this possible? if so can someone please help

    Button Name: BTNChangeDate
    Lable Name: LBLDate



    thanks in advance

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    You can accomplish what you ask with the following.
    Code:
    Dim MyDate As Date
    MyDate = InputBox("Please enter a date", "Date Needed")
    However, I would advise against using an input box. You will not be guaranteed the User will type an actual date. It would be better to use a TextBox Control formatted as date. So maybe put a control on your existing form or have a second form open in pop-up mode. Also, be aware that data type date in Access is formatted like mm/dd/yy or mm/dd/yyyy.

  3. #3
    stu_C is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Mar 2010
    Posts
    38
    Hello
    thanks for the help, maybe I am doing something wrong, I resume where is says mydate I replace that with the name of the Label field?, I done the below code, the dialogue box pops up but doesnt change the text on the field :\


    Code:
    Private Sub BTNChangeDate_Click()

    Dim LBLDate As Date
    LBLDate = InputBox("Please enter a date", "Date Needed")

    End Sub



    Quote Originally Posted by ItsMe View Post
    You can accomplish what you ask with the following.
    Code:
    Dim MyDate As Date
    MyDate = InputBox("Please enter a date", "Date Needed")
    However, I would advise against using an input box. You will not be guaranteed the User will type an actual date. It would be better to use a TextBox Control formatted as date. So maybe put a control on your existing form or have a second form open in pop-up mode. Also, be aware that data type date in Access is formatted like mm/dd/yy or mm/dd/yyyy.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    For textbox controls, you would assign a value to the .Value property. For labels you would assign a value to the .Caption property.

    So something like ...
    Code:
    Dim MyDate As Date
    MyDate = InputBox("Please enter a date", "Date Needed")
    Me.LBLDate .Caption = MyDate
    You would also add some code to catch any errors. For instance, the user may type in a value that is not an actual date.

    Another approach would be to assign whatever the user types into the input box to the label's caption property.
    Code:
    Me.LBLDate.Caption = InputBox("Please enter a date", "Date Needed")

  5. #5
    stu_C is offline Advanced Beginner
    Windows XP Access 2003
    Join Date
    Mar 2010
    Posts
    38
    Hello ItsMe
    thanks so much for the code, only problem is when I close the report and reopen it the date disappears which ideally would like it to be saved until chnaged again, I have a macro you click to close the report which automatcially saves it but still no joy

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Did you create a Macro or did you build some VBA code? Can you show the code here? Are you clicking a button before closing the report? What does the button use, VBA or a Macro?

  7. #7
    stu_C is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    38
    Hello,
    any way I do it doesnt seem to save it, even if I click File > save and close the report it doesnt save the changed date.... very strange...

    the two buttons are as followed:

    Change date in lable Button:
    Private Sub Command73_Click()
    Dim MyDate As Date
    MyDate = InputBox("Please enter a date", "Date Needed")
    Me.LBLDate.Caption = MyDate
    End Sub

    Close Report Button:
    Just used the create wizard
    Action: Save & Close

    like I said even when I save manualy and close the report is still happens

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Code behind a form or report will execute during Run Time. When you have a report open in Report View and the User is interacting with it, this is Run Time. Any changes that will be saved to the Caption property of a label must be made during Design Time.

    In order to use code to make Design Time changes to an object, the code must be executed from another object/module. In other words, a report cannot be in both Run Time and Design Time at the same time. So you could execute code like the following from a form called "MyOtherForm", while MyOtherForm is in Run Time
    Code:
    DoCmd.OpenForm "FormName", acDesign
    Me.lblOne.Caption = "some text"
    DoCmd.Save acForm, "FormName"
    What the above code is doing is opening a form in design time and assigning a value to the Caption property of a label. Because the other form is open in design time mode, the Save method can be used on it and the design changes can be saved.

    What you should do is use a column in a table to store the date you need. Any data that needs to be stored should be stored in a table. This is your persistent data. Data that is not volatile should be stored in tables. You can bind a control to a table or query to store the date provided by the User input.

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

Similar Threads

  1. Replies: 3
    Last Post: 06-30-2015, 08:10 AM
  2. Replies: 2
    Last Post: 10-03-2014, 10:07 AM
  3. Replies: 2
    Last Post: 08-21-2013, 05:30 PM
  4. Replies: 2
    Last Post: 10-19-2011, 03:21 AM
  5. Replies: 0
    Last Post: 01-12-2011, 12:43 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