Setting a Default Value

D

DS

I need to change the default value of a field in a table, well actually
2 fields the StartDate and the EndDate. This would be done every
morning at the start of the business day. So I thought this would work.
But I'm getting "Item Not Found" Am I missing something!
Thanks
DS

CurrentDb.TableDefs("tblDefault")!Fields("TestStartDate").DefaultValue =
Date + 1
 
D

DS

DS said:
I need to change the default value of a field in a table, well actually
2 fields the StartDate and the EndDate. This would be done every
morning at the start of the business day. So I thought this would work.
But I'm getting "Item Not Found" Am I missing something!
Thanks
DS

CurrentDb.TableDefs("tblDefault")!Fields("TestStartDate").DefaultValue =
Date + 1
OK I got this to almost work, the problem is that it's not putting in
the date its putting in the time!

Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field

Me.TxtStart = Date
Me.TxtEnd = Date + 1

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

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

Any Help appreciated.
Thanks
DS
 
M

Marshall Barton

DS said:
OK I got this to almost work, the problem is that it's not putting in
the date its putting in the time!

Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field

Me.TxtStart = Date
Me.TxtEnd = Date + 1

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

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


The DefaultValue is a text string so it needs to be
formatted approppriately:

Dim db As DAO.Database

Set db = CurrentDb
With db.TableDefs("tblDefault")
.Fields("TestStartDate").DefaultValue = _
Format(Date, "\#m\/d\/yyyy\#")
.Fields("TestEndDate").DefaultValue = _
Format(Date+1, "\#m\/d\/yyyy\#")
End With
 

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