Results 1 to 9 of 9
  1. #1
    Daisy509th's Avatar
    Daisy509th is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Location
    Central Texas
    Posts
    51

    Date manipulation

    If IsNull(Me.Combo203) Then Exit Sub


    strPresentation = "D:\Users\druss\Lauren Concrete\Digtal Libary-DOT Paperwork\Drivers" & Me.Combo203 & "" & DatePart("yyyy", #3/17/2018#) & "TS" & ".pdf"
    Me.Text229 = strPresentation

    the datepart is returning what i asked it to do which is the year "2018". My problem is I need to return "3172018". DatePart("m""d""yyyy", #3/17/2018#) and this doesnt work.

    I also need to be able to do this from an unbound textbox with a datepicker.

    Thanks

  2. #2
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    If you are hard coding the date, you may as well write the value 3172018 yourself.
    Otherwise use
    Code:
    Format([DateField],"mdyyyy")
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  3. #3
    Daisy509th's Avatar
    Daisy509th is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Location
    Central Texas
    Posts
    51
    DatePart("yyyy", Textbox197) I am trying to pull this from a textbox because the user will be picking different dates.I need "3172018" and the next time it maybe "412018". This is the naming nomenclature for the .pdf

  4. #4
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,977
    I assumed that was the case.
    DatePart function are used to pull one section of a date field e.g. DatePart("yyyy", Textbox197) ; DatePart("m", Textbox197)
    As already explained, to modify the order of the whole date field, use
    Code:
    Format([DateField],"mdyyyy")
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  5. #5
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I think what's wanted is like this (modified so as to not make one looonnnnngggg expression
    Code:
    Dim strMonth As String, strDay As String, strYear As String
    
    strMonth = Month(#3/17/2018#)
    strDay = Day(#3/17/2018#)
    strYear = Year(#3/17/2018#)
    
    strPresentation = "D:\Users\druss\Lauren Concrete\Digtal Libary-DOT Paperwork\Drivers" & Me.Combo203 & ""
    strPresentation = strPresentation & strDay & strMonth & strYear & "TS" & ".pdf"
    not that I get the reason for concatenating an empty string. I think the functions I used are a bit more succinct than DatePart.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    Daisy509th's Avatar
    Daisy509th is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Location
    Central Texas
    Posts
    51
    Private Sub cmdTeamSummaryDates_Click()


    Dim strMonth As String, strDay As String, strYear As String, strPresentation As String


    strMonth = DatePart("m", Me.Combo197)
    strDay = DatePart("d", Me.Combo197)
    strYear = DatePart("yyyy", Me.Combo197)


    If IsNull(Me.Combo233) Then Exit Sub


    MsgBox Me.Combo233
    strPresentation = "D:\Users\druss\Lauren Concrete\Digtal Libary-DOT Paperwork\Drivers" & Me.Combo233 & "" & ""
    strPresentation = strPresentation & strMonth & strDay & strYear & "TS" & ".pdf"
    Me.Text229 = strPresentation




    End Sub

    Thanks for the help

  7. #7
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I take it that problem is solved.
    Interesting that you stuck with the DatePart function. Just a matter of preference, I suppose.
    Wondering - 6 months or maybe longer from now, will you be able to quickly differentiate between combo197 and combo223 without having to read through your code to figure out which is holding what info? You might want to consider using a more intuitive naming convention.

  8. #8
    Daisy509th's Avatar
    Daisy509th is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Location
    Central Texas
    Posts
    51
    Dim strMonth As String, strDay As String, strYear As String


    strMonth = Month(#3/17/2018#)
    strDay = Day(#3/17/2018#)
    strYear = Year(#3/17/2018#)


    strPresentation = "D:\Users\druss\Lauren Concrete\Digtal Libary-DOT Paperwork\Drivers" & Me.Combo203 & ""
    strPresentation = strPresentation & strDay & strMonth & strYear & "TS" & ".pdf"

    I couldn't get this to work. I put me.Combo197 where #3/17/2018# was but it didnt return part of the date.
    You are also correct about the naming so I am going through and naming things with a more intuitive name.
    I dont know if you can help me with error correction but I have just read I need to be doing that also

  9. #9
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I put me.Combo197 where #3/17/2018# was but it didnt return part of the date.
    Always post what you tried if you want help or info about it, and be specific about where you tried it, otherwise, we're just guessing. When using this function in vba, you can do what you did as in
    Msgbox Year(Me.Combo197), but in sql, delimiters are usually required when using references whose data type is a date or text. However, what I see doesn't appear to be sql, but rather is a string variable that represents a file path, so I don't see date delimiters being required. Note also that if you have created a variable for something, it's usually more efficient to use it rather than a control reference. Meaning you have strYear, or strMonth, or strDay so why use Me.Combo197 instead?

    strPresentation = "D:\Users\druss\Lauren Concrete\Digtal Libary-DOT Paperwork\Drivers" & strYear & ""...

    Don't know what you mean by "error correction". You mean error trapping?

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

Similar Threads

  1. Text box Manipulation
    By HelpDesk in forum Access
    Replies: 5
    Last Post: 06-26-2015, 12:53 PM
  2. Data Manipulation
    By Thompyt in forum Programming
    Replies: 7
    Last Post: 03-27-2015, 05:32 PM
  3. Date data manipulation
    By Duncan in forum Access
    Replies: 3
    Last Post: 03-09-2012, 11:13 PM
  4. date manipulation
    By lpsd in forum Access
    Replies: 3
    Last Post: 12-23-2010, 12:06 PM
  5. Query manipulation using VBA
    By benattal in forum Programming
    Replies: 0
    Last Post: 12-31-2008, 09:12 AM

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