Results 1 to 13 of 13

Thread: Help: Help on Access, how to make Date/Time to just Date?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Posts
    131

    Exclamation Help: Help on Access, how to make Date/Time to just Date?

    Good morning, I just need the Date format on Access but the list of data tye only has Date/Time is there anyway to change ot just Date. I need to change it to date only because when I transfer a recorset to Excel, it inlcudes the time as well which is not needed.

    God bless,
    Alvin

  2. #2
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188
    Hi Alvin,

    After selecting Date/Time as the field type change the Format property of that field to Short Date or whatever.

    ciao
    b

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Posts
    131

    Tried that already

    Thanks for the reply but it's set like that already. Is there any more data type like a plug-in for Access where there is only the Date and not Date/time?

    Any work around for this. I just can't transfer the recordset to Excel with the time on it, it will ruin the print out when the user prints it out (not to mention wasting ink on very big print outs) as the date is the only one needed.

    God bless,
    Alvin

  4. #4
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478
    If it is a recordset your transfering you could just get the date wihtout the time.

    Will search the syntax for you.
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

  5. #5
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343
    Format the cell in excel to dd mmm yyyy....

    Code it in if you want to...


    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    From Access you can just put a format in your query, eg:

    SELECT Format(<DateTimeField>,'dd/mm/yyyy'), ...

  7. #7
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343
    Si,

    If you did that it might put it in excel as text (I did that before) then the sorting in excel won't work right.

    Best idea is put it in with date/time. tehn format the Excel cell to the format required.



    Vince
    (Although I found yesterday that excel is soooooooooo helpful when typing things in cells. . like assuming lots of things for you :/ )

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Posts
    131

    How to format Excel

    Thanks again for th reply but how do you format Excel to just have the Date and disregard the time after being trasferred from the recordset.

    The program I'm making is not for me. Is there a more automatic way to disregard the Time. They might not want have the Excel's setting changed for their other normal sheets.

    How come Access has to put in the the time in date and why doesn't it have just a pure date data type btw?


    God bless,
    Alvin

  9. #9
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343
    The date is stored the same way in both excel and access.

    Its a number.

    If you don't believe me - type a date into excel and change the formatting to general. It should go to a number (unless it classed it as text in which case it won't change).

    How are you putting the data into the cells? Manual code or via excels recordset transfer?

    If manual code you need to add (or soemthing similar as this is direct from excel):
    VB Code:
    1. Selection.NumberFormat = "dd mmm yyyy"

    So probably - objExcel.Selection.NumberFormat = "dd mmm yyyy"

    If you've transferred out from access or anything then the user can change the formatting and look of the excel sheet - if they can't do this they need to learn how.


    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Posts
    131

    Thanks for the reply

    Thanks again for the replies. I don't really know how to use Excel (I'm not even at the beginner level) application itself.

    This is the code I use to transfer the recordset from vb to Excel, most I got from the forum. The dates in Access are date/time short date ( I just wished it just had Date only, to make it easier):

    Private Sub mnuFileExcel_Click()
    'Check dates first
    If IsDate(txtFrom.Text) = False Then
    intMsg = MsgBox("Check date if it's correct", vbOKOnly, Empty)
    txtFrom.SetFocus
    Exit Sub
    End If

    If IsDate(txtTo.Text) = False Then
    intMsg = MsgBox("Check date if it's correct", vbOKOnly, Empty)
    txtTo.SetFocus
    Exit Sub
    End If
    Me.MousePointer = 11
    '-------------------------------------------------------
    'Check first if there is a record to save
    Set d = OpenDatabase(App.Path & "\Parts Inventory.mdb")
    Set r = d.OpenRecordset("SELECT * FROM [Receiving Table] WHERE Received BETWEEN #" & txtFrom & "# AND #" & txtTo & "#")
    r.Requery

    'If no record is found
    If r.RecordCount = 0 Then
    intMsg = MsgBox("There are no records to save yet", vbOKOnly + vbExclamation, Empty)
    Me.MousePointer = 0
    Exit Sub
    End If
    '-------------------------------------------------------

    Set d = OpenDatabase(App.Path & "\Parts Inventory.mdb")
    Set r = d.OpenRecordset("SELECT * FROM [Receiving Table] WHERE Received BETWEEN #" & txtFrom & "# AND #" & txtTo & "#")


    Dim x As New Excel.Application

    x.Application.DisplayAlerts = False
    x.Visible = False

    Dim w As Worksheet
    x.Workbooks.Add
    Set w = x.Worksheets(1)
    Set q = w.QueryTables.Add(r, w.Range("A1"))
    q.Refresh (True)

    On Error GoTo err
    x.Workbooks.Application.SaveWorkspace ' ("c:\pibkrecv.xls")
    x.Quit
    MsgBox "It has been saved", vbInformation, Empty
    Me.MousePointer = 0
    'x.SaveChanges = False


    Set d = Nothing
    Set r = Nothing
    On Error GoTo exit2

    exit2:
    Exit Sub
    MsgBox "Error", vbInformation, "Not Saved, Excel application may not have been installed"
    Me.MousePointer = 0

    'Should the user click Cancel in the save dialog box
    err:
    Exit Sub
    Me.MousePointer = 0
    End Sub

  11. #11
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Thanks for the reply

    You'd need to make a selection first...
    VB Code:
    1. objExcel.Selection.NumberFormat = "dd mmm yyyy"

    Is the querytables a fast transfer? I'm asking because I use a loop through the recordset and move to teh cells writting the data in - this is slow though and I would like to know if the querytables is faster... Excel help hasn't been installed here at work so thats no use to me.


    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  12. #12
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    Ecniv, do you write one cell at a time? If you do this is about 10 times quicker (obviously depending on how many columns you are getting)

    VB Code:
    1. 'rowMin = First row to write to
    2. 'num_fields = RecSet.Fields.Count
    3. 'tmp_val = Number of rows of data to write
    4. '"field_type" returns Text for any text based field (text/char etc)
    5. '"xlCol" returns the column letter (eg: 1 gives A, 26 gives Z etc)
    6.   start_row = rowMin
    7.   ReDim tmp_xl_array(tmp_val, num_fields)
    8.   tmp_str = ":" & xlCol(num_fields + colMin - 1)
    9.   tmp_str2 = xlCol(colMin)
    10.   Do While Not (RecSet.EOF)
    11.     For I = 0 To num_fields - 1
    12.       If Not (IsNull(RecSet(I))) Then
    13.         If field_type(RecSet(I), RetMajor:=True) = "Text" Then t = "'"
    14.       End If
    15.       tmp_xl_array(rowMin - start_row, I) = t & Trim(CStr("" & RecSet(I)))
    16.     Next I
    17.     RecSet.MoveNext
    18.     rowMin = rowMin + 1
    19.     If rowMin Mod 25 = 0 Then DoEvents
    20.   Loop
    21.   tmp_row = rowMin - start_row - 1
    22.   rowMin = tmp_row + start_row
    23.   .Range((tmp_str2 & CStr(start_row) & tmp_str & CStr(rowMin))) = tmp_xl_array

  13. #13
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343
    So you can set an array to the range??

    Neat - I'll have a go later

    Thanks


    Vince

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width