Set Control Defaults

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like to automatically set the default value of a field in a table
(InvoiceDate) each month when we create invoices to be the 20th of the
current month. I do it manually now by going into design view of the table
and manually typing in the new date. Is there a way to do this using code or
a macro from the form I already have open? I'd like to click a button on the
form and it automatically change the default date for [InvoiceDate] in the
Invoice table to the 20th of the current month.

I've played around with:
docmd.RunCommand acCmdSetControlDefaults
in the module for the form, but can't figure out how to make it work (if it
is even possible).

Thanks for any advice!
Susan
 
In
Susan said:
I would like to automatically set the default value of a field in a
table (InvoiceDate) each month when we create invoices to be the 20th
of the current month. I do it manually now by going into design view
of the table and manually typing in the new date. Is there a way to
do this using code or a macro from the form I already have open? I'd
like to click a button on the form and it automatically change the
default date for [InvoiceDate] in the Invoice table to the 20th of
the current month.

I've played around with:
docmd.RunCommand acCmdSetControlDefaults
in the module for the form, but can't figure out how to make it work
(if it is even possible).

Is the InvoiceDate present on the form from which you're entering
invoices? If so, it sounds to me like maybe all you need to do is set
the DefaultValue property of the text box that is bound to that field to
something like

DateSerial(Year(Date()),Month(Date()),20)

That won't affect entries into the table that aren't made from this
form, though.
 
Thanks for the quick reply! No, the InvoiceDate is not on this form. This
form is sort of like a Menu that has no control source, just buttons that run
certain processes in the order needed. The only part I haven't figured out
how to automate is setting the default value of this date field in the table
so that when we create the invoices, they all have the correct date.

I was trying to see if there is a way to change the default value of a field
in a table using code in a form (not containing that table).

Dirk Goldgar said:
In
Susan said:
I would like to automatically set the default value of a field in a
table (InvoiceDate) each month when we create invoices to be the 20th
of the current month. I do it manually now by going into design view
of the table and manually typing in the new date. Is there a way to
do this using code or a macro from the form I already have open? I'd
like to click a button on the form and it automatically change the
default date for [InvoiceDate] in the Invoice table to the 20th of
the current month.

I've played around with:
docmd.RunCommand acCmdSetControlDefaults
in the module for the form, but can't figure out how to make it work
(if it is even possible).

Is the InvoiceDate present on the form from which you're entering
invoices? If so, it sounds to me like maybe all you need to do is set
the DefaultValue property of the text box that is bound to that field to
something like

DateSerial(Year(Date()),Month(Date()),20)

That won't affect entries into the table that aren't made from this
form, though.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
I did some more experimenting with your suggestion, and I actually am looking
at the Invoice table from a form that I can use your method to set the
default value from that form and it looks like it will work perfectly!!
Thanks so much!!
Susan

Dirk Goldgar said:
In
Susan said:
I would like to automatically set the default value of a field in a
table (InvoiceDate) each month when we create invoices to be the 20th
of the current month. I do it manually now by going into design view
of the table and manually typing in the new date. Is there a way to
do this using code or a macro from the form I already have open? I'd
like to click a button on the form and it automatically change the
default date for [InvoiceDate] in the Invoice table to the 20th of
the current month.

I've played around with:
docmd.RunCommand acCmdSetControlDefaults
in the module for the form, but can't figure out how to make it work
(if it is even possible).

Is the InvoiceDate present on the form from which you're entering
invoices? If so, it sounds to me like maybe all you need to do is set
the DefaultValue property of the text box that is bound to that field to
something like

DateSerial(Year(Date()),Month(Date()),20)

That won't affect entries into the table that aren't made from this
form, though.

--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Back
Top