DATE Problem

D

DS

I can't seem to store a date.
Here is the scenerio.

Me.TxtStart = Date()

Set db = CurrentDb
Set tdf = db.TableDefs("tblDefault")
Set fld = tdf.Fields("TestStartDate")
fld.DefaultValue = Me.TxtStart


Whats being set in the TestStartDate field is the time! I need the date
thats in the Me.TxtStart field.

Any help appreciated.
Thanks
DS
 
S

storrboy

I can't seem to store a date.
Here is the scenerio.

Me.TxtStart = Date()

Set db = CurrentDb
Set tdf = db.TableDefs("tblDefault")
Set fld = tdf.Fields("TestStartDate")
fld.DefaultValue = Me.TxtStart

Whats being set in the TestStartDate field is the time! I need the date
thats in the Me.TxtStart field.

Any help appreciated.
Thanks
DS


1) What is the format of the field in question set to? A time or date
format?
2) Your code is attempting to set the default value of the field, not
the value for that record. Why are you trying to do it this way? If
the form is bound to the table, then just bind the control to the
appropriate field. Any value entered in that control will be saved to
the table. If the form is not bound, then try running an update query
to do it instead - DoCmd.RunSql
 
D

DS

storrboy said:
1) What is the format of the field in question set to? A time or date
format?
2) Your code is attempting to set the default value of the field, not
the value for that record. Why are you trying to do it this way? If
the form is bound to the table, then just bind the control to the
appropriate field. Any value entered in that control will be saved to
the table. If the form is not bound, then try running an update query
to do it instead - DoCmd.RunSql
Correct I am trying to set the default value of the field. The form is
unbound. Can I set the default value with SQL?
Thnaks
DS
 
D

DS

DS said:
Correct I am trying to set the default value of the field. The form is
unbound. Can I set the default value with SQL?
Thnaks
DS
PS from DS,
The format of the field is Date/Time.
 
M

Marshall Barton

DS said:
I can't seem to store a date.
Here is the scenerio.

Me.TxtStart = Date()

Set db = CurrentDb
Set tdf = db.TableDefs("tblDefault")
Set fld = tdf.Fields("TestStartDate")
fld.DefaultValue = Me.TxtStart


Whats being set in the TestStartDate field is the time! I need the date
thats in the Me.TxtStart field.

That's not a time, it's the result of the divisions 4
divided by 11 divided by 2007.

See your earlier post for an explanation of how to set the
default value.
 
D

DS

Marshall said:
DS wrote:




That's not a time, it's the result of the divisions 4
divided by 11 divided by 2007.

See your earlier post for an explanation of how to set the
default value.
Thanks Marshall,
I came up with this, it works!
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field

Me.TxtBDayStart = DLookup("BDayStart", "tblHours", "BDayStart=" & Me.TxtNow)
Me.TxtBDayEnd = DLookup("BDayEnd", "tblHours", "BDayStart=" & Me.TxtNow)
If Me.TxtBDayStart = Me.TxtBDayEnd Then
Me.TxtStart = Date
Me.TxtEnd = Date
ElseIf Me.TxtBDayStart < Me.TxtBDayEnd Then
Me.TxtStart = Date
Me.TxtEnd = Date + 1
End If



Set db = CurrentDb
Set tdf = db.TableDefs("tblDefault")
Set fld = tdf.Fields("TestStartDate")
fld.DefaultValue = Format(Me.TxtStart, "##")

Set tdf = db.TableDefs("tblDefault")
Set fld = tdf.Fields("TestEndDate")
fld.DefaultValue = Format(Me.TxtEnd, "##")

Now I'm going to try yours! I'll probably go with yours since you are
defintly more knowledgeable than I!
Once again,
Thank you very much!
DS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top