Results 1 to 13 of 13
  1. #1
    Join Date
    Mar 2004
    Posts
    287

    Unanswered: Calender Control

    I have a calender control in Module as below which brings up a calender, allows me to select a date then transfer the select date to a date file in my form record. What I want to know is I also need it to record the time, which can be =now() but at the moment the data it chucks across is just
    the date where i need the general date (date/time)

    also, how do i use the IF statement to check whether a field has any data in it (Null?)

    here's the calender module code;
    Code:
    Public Function acbGetDate(varDate As Variant) As Variant
    
        Const acbcCalForm = "Calendar"
        
        ' Open calendar form in dialog mode
        ' passing it the current date using OpenArgs
        DoCmd.OpenForm acbcCalForm, WindowMode:=acDialog, _
         OpenArgs:=Nz(varDate)
        
        ' Check if the form is open; if so return the date
        ' selected in the calendar control and close the
        ' popup calendar form and pass the new date back
        ' to the control. Otherwise, just return a null.
        If IsOpen(acbcCalForm) Then
            acbGetDate = Forms(acbcCalForm).CalDate
            DoCmd.Close acForm, acbcCalForm
        Else
            acbGetDate = Null
        End If
    End Function
    Any help would be appreciated.

  2. #2
    Join Date
    Mar 2004
    Posts
    287
    it appears the links for the date field are in the calender form;
    Code:
        Me!ocxCal = datDate
    datDate is chucked back to the main form which inserts the selected date from the calender.

    With this in mind, how do i change the format for the datDate to a GeneralDate?

  3. #3
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Look at the Format() function...
    George
    Home | Blog

  4. #4
    Join Date
    May 2005
    Posts
    1,191
    Quote Originally Posted by NeilMansell
    also, how do i use the IF statement to check whether a field has any data in it (Null?)
    Check out the Nz() function
    Me.Geek = True

  5. #5
    Join Date
    Mar 2004
    Posts
    287
    right i can't seem to find where to change the format setting.. here's my calender form which grabs a date selected by the user;

    Code:
    Public Property Let CalDate(datDate As Date)
        Me!ocxCal = datDate
    End Property
    
    Public Property Get CalDate() As Date
        CalDate = Me!ocxCal
    End Property
    
    Private Sub cmdCancel_Click()
        DoCmd.Close acForm, Me.Name
    End Sub
    
    Private Sub cmdNextMonth_Click()
        Me!ocxCal.NextMonth
        Me.Repaint
    End Sub
    
    Private Sub cmdNextYear_Click()
        Me!ocxCal.NextYear
        Me.Repaint
    End Sub
    
    Private Sub cmdOK_Click()
        Me.Visible = False
    End Sub
    
    Private Sub cmdPrevMonth_Click()
        Me!ocxCal.PreviousMonth
        Me.Repaint
    End Sub
    
    Private Sub cmdPrevYear_Click()
        Me!ocxCal.PreviousYear
        Me.Repaint
    End Sub
    
    Private Sub cmdToday_Click()
        Me!ocxCal.today
    End Sub
    
    Private Sub Form_Load()
        If Not IsNull(Me.OpenArgs) Then
            Me.CalDate = Me.OpenArgs
        End If
    End Sub
    
    Private Sub ocxCal_DblClick()
        Call cmdOK_Click
    End Sub
    and here's the calender button code on the form;
    Code:
    Private Sub btncboDateFrom_Click()
        Dim ctlDate As TextBox
        Dim varReturn As Variant
        
        Set ctlDate = Me!SelectRecDate
        varReturn = acbGetDate(ctlDate.Value)
        
         
        If Not IsNull(varReturn) Then
            ctlDate = varReturn
        End If
        
        
    [Received] = [SelectRecDate]
    [SelectRecTime] = Now()
    
    End Sub
    Can anyone point me in the right direction of how to make it so the date is full length on the form (I need it to be passed on RECEIVED field)

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    CDate(<mycontrol>)
    but Id want to check it was a date first...

    if isdate(<mycontrol>) then dateValue=CDate(<mycontrol>)
    I'd rather be riding on the Tiger 800 or the Norton

  7. #7
    Join Date
    Mar 2004
    Posts
    287
    Thanks.

    Wherebouts to place it though please?

  8. #8
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    the standard access /office calendar control dopesn't support times if I remember correctly, you will need to identify the hours / minutes / seconds separately

    like most computer systres / database engines the native data format for access and VBA doesn't directly support the idea of a time, what they do do is store the number of ticks form a specific date. in access's case the integer element identifies the number of days from a sepcific date, the decimal part the number of ticks which resolves to the hours / minutes / seconds of the day.

    so if you dont supply a time element as part of your calendar value Access will store the value as being midnight on the start of the day ie 00:00, most computer clocks do not recognise 24:00 or midnight they see that date as being the start of the next day.


    id suggest you haev a look at the help system for date/time concepts
    I'd rather be riding on the Tiger 800 or the Norton

  9. #9
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    sorry if i have lost the plot here!

    selecting a date in calendar: fine!
    ...but why should the time associated with the selected calendar date come from Now()

    either input the time explicitly, or use Now() for the whole operation.

    izy
    currently using SS 2008R2

  10. #10
    Join Date
    May 2005
    Location
    Nevada, USA
    Posts
    2,888
    Provided Answers: 6
    There's a free calendar control that also does time here:

    http://www.mdbmakers.com/forums/showthread.php?t=9423
    Paul

  11. #11
    Join Date
    Mar 2004
    Posts
    287
    yeah i thought the same using the now() function but i need to take the caldate and time and place into a long date field, i have tried caldate + time but it displays an incorrect date like that - how can i do that please.

    basically what i require the end result to be is i have one main field (grabbed from the email) date (long date with time)
    but i need the user to edit the date and time, in which case I have split the date up into date and time but i still require the original date to be editable with the new data, so if anyone else has work arounds i would be happy to listen and try...

    Basically i need to edit a long date and time field, either edit the date or edit the time (using the calender also which only edits the date)

    eg: [Received] = [SelectRecDate] & Now()
    Received is the original date (long date with time) and the SelectRecDate is the date, now() is time now.
    Last edited by NeilMansell; 04-17-07 at 05:58.

  12. #12
    Join Date
    Mar 2004
    Posts
    287
    nevermind, the new calender link works perfectly - allowing me to edit the original RECEIVED field - thanks for the help guys!!

    I wanted to solve the problem but think this is the best option as I have a long way to go before completing the database for usage.

    thanks.

  13. #13
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    have a look at the date /time functions in the help system

    you may have to go round the houses to build a new date time value

    eg
    Code:
    mynewdatetimevalue = CDate("01/11/2006  " & Format(Now(), "Hh:Nn:Ss"))
    or possibly
    Code:
    mynewdatetimevalue = CDate(format(mynewdatevalue,"dd mm yyyy") & "  " & Format(Now(), "Hh:Nn:Ss"))
    you could of course 'just' set the correct integer value to define the day/month year, and the correct decimal value to describe the time element..... but thats another story
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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