Full Version: Dim Function To Display Todays Date
UtterAccess Forums > Microsoft® Access > Access Forms
djleister
I am using the DIM function as:
v1 = Me!DATA_ENTRY = Now(). I have even tried DateTime.Now
However it displays 12/30/1899 instead of todays date
Any suggestions?
WildBird
You cant have 2 = signs on same statement.
That is the full code? You mention DIM statement, but dont show it here.
Doug Steele
Sorry, but there is no DIM function. Dim is a statement that declares a variable.
The line of code you're showing is setting v1 (whatever it is) to the results of the comparison between whatever's contained in control Me!DATA_ENTRY and the current value returned by the Now() function. Since it's extremely unlikely that DATA_ENTRY is going to contain the current date and time (to the second), that's almost always going to be 0, which happens to be the date 30 Dec, 1899 to Access (Dates are 8 byte floating point values, where the integer portion represents the date as the number of days relative to 30 Dec, 1899, and the decimal portion represents the time as a fraction of a day). In the unlikely event that DATA_ENTRY did contain the same value returned by the Now() function, your equation would return 12/29/1899 (since True is -1 to VBA, and -1 is 29 Dec, 1899 as a date)
I think you're going to have to provide more context for what it is you're trying to do. Presumably the line of code you cited is part of a larger routine. What is that routine?
djleister
Private Sub CmbConvert_Click()
e.Link = [HistoryID]
Me.ChgType.Enabled = True
Me.DocNum.Enabled = True
Me.DocDate.Enabled = True
Me.RecDate.Enabled = True
Me.Label63.Visible = True
Me.ChkCO.Visible = True
Me.ChkCOR.Visible = True
Me.ChkCOP.Visible = True
Me.ChkCPM.Visible = True
Me.ChkROM.Visible = True
Me.Box62.Visible = True
Me.Status = "CLOSED"
Me.Link = [HistoryID]
Dim v1 As Variant
Dim v2 As Variant
Dim v3 As Variant
Dim v4 As Variant
Dim v5 As Variant
Dim v6 As Variant
Dim v7 As Variant
Dim v8 As Variant
Dim v9 As Variant
Dim v10 As Variant
Dim v11 As Variant
Dim v12 As Variant
Dim v13 As Variant
Dim v14 As Variant
Dim v15 As Variant
Dim v16 As Variant
v1 = Me!DATA_ENTRY (this is where I need it to display todays date)
v2 = Me!DocNum.Value
v3 = Me!DocDate.Value
v4 = Me!RecDate.Value
v5 = Me!SentDate.Value
v6 = Me!Amt.Value
v7 = Me!Estimate.Value
v8 = Me!AuthAmt.Value
v9 = Me!AE_STATUS.Value
v10 = Me!Initiator.Value
v11 = Me!TimeExt.Value
v12 = Me!Link.Value
v13 = Me!ContractID.Value
v14 = Me!Desc.Value
v15 = Me.COMMENTS.Value
v16 = Me!Like.Value
RunCommand acCmdRecordsGoToNew
Me!DATA_ENTRY = v1
Me!DocNum = v2
Me!DocDate = v3
Me!RecDate = v4
Me!SentDate = v5
Me!Amt = v6
Me!Estimate = v7
Me!AuthAmt = v8
Me!AE_STATUS = v9
Me!Initiator = v10
Me!TimeExt = v11
Me!Link = v12
Me!ContractID = v13
Me!Desc = v14
Me!COMMENTS = v15
Me!Like = v16

Me.Status = "OPEN"
Me.ChgType.SetFocus
Me.AllowEdits = True
Me.Refresh
End Sub
MikeLyons
It appears you want the current date as a default for that field in a new record on a form? If so, just set the textbox's DefaultValue to =Date() (or =Now() if you want the time as well)
dit: Looking at it again it kind of looks like you want each new record to be essentially a copy of the last -- is that so? If so, why? Generally, redundant data is a bad thing in a database.
Mike
djleister
Thanks Mike that worked.
appreciate your concern about redundant information; however since this is a public agency, when duplicating a record in an effort to create the next change type it is required to keep the original document and link it as it progresses through the change process.
Thank you for your help.............................I did already have it as a default =Now() so just removing the dim code for that field did the trick.
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.