Results 1 to 8 of 8
  1. #1
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276

    Save Date As Text

    I have a button if I clik on it, it should change the month to previous month in the text field "dtetxt" the control source of this text field is "Salary Month". With the following code it chages it to 01/11/2022 and save the "Salary Month" as 01/11/2022. Where it should save same as November.




    Private Sub Pmonth_Click()


    Me.dtetxt = DateAdd("m", -1, [Purchase Date])


    End Sub

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,927
    So use the Format() function?
    However you can format it as you want when you want to see it? and leave it as a date.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    I dont want to leave it as a date. I just need it to save as name of the month.

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,927
    Quote Originally Posted by aamer View Post
    I dont want to leave it as a date. I just need it to save as name of the month.
    So use the Format() function?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,412
    See if you can work with this:

    me.dtetxt = Monthname(Month(DateAdd("m", -1, #1/11/2022#)))

    You'll have to replace the literal 1/11/22 with your variable. It may or may not require the # delimeters, depending on its data type.

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,927
    Well I was just thinking of
    Code:
    Me.dtetxt = Format([Purchase Date],"mmmm")
    However, again, is this not a calculated value?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    aamer is offline Competent Performer
    Windows 7 Access 2007
    Join Date
    Jul 2010
    Location
    Pakistan
    Posts
    276
    Quote Originally Posted by davegri View Post
    See if you can work with this:

    me.dtetxt = Monthname(Month(DateAdd("m", -1, #1/11/2022#)))

    You'll have to replace the literal 1/11/22 with your variable. It may or may not require the # delimeters, depending on its data type.
    Tried This

    Private Sub Pmonth_Click()


    Me.dtetxt = MonthName(Month(DateAdd("m", -1, [Purchase Date])))


    End Sub


    Works Perfect

  8. #8
    davegri's Avatar
    davegri is offline Excess Access
    Windows 11 Access 2019
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,412
    Good to hear. Good luck with the project.

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

Similar Threads

  1. Text box calculations to save in table
    By chr1stoper1 in forum Forms
    Replies: 3
    Last Post: 06-21-2019, 01:14 PM
  2. Forcing unbound text box to save it's value
    By DDS in forum Programming
    Replies: 8
    Last Post: 06-17-2018, 01:03 PM
  3. Save some text fields and clear others
    By whisp0214 in forum Forms
    Replies: 9
    Last Post: 10-25-2017, 03:48 PM
  4. Replies: 12
    Last Post: 03-27-2014, 04:49 AM
  5. Replies: 2
    Last Post: 03-01-2012, 12:21 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