Setting a Default Value

  • Thread starter Thread starter DS
  • Start date Start date
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
 
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
 
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
 
Back
Top