Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

force date entry fom a cmd button

Status
Not open for further replies.

thefroggy

Technical User
Apr 20, 2004
31
GB
Hi everyone,

Here is my problem. I have created a database to store information on raw material stored in a ware house. Each class of raw material have a given expire date, and some of my user are messing up this vital information when a new raw is introduced.

Have a starting form with different cmd buttons (Cmd1, Cmd2…) all opening the same form (mainform) with common information to enter, but also activates different sub forms depending on the raw material in question.

So:

Cmd1 open mainform + subform1 (with expire date 6 months)
Cmd2 open mainform + subform2 (with expire date 1 year)

Depending on the Cmd clicked, expire date will be different and I would like to remove the human error and automatically enter expire date from a cmd click.

I have been trying something like that:

DoCmd.OpenForm "mainform"
DoCmd.GoToRecord , "mainform", acNewRec
Forms![mainform]!text1.Value = "text"
Forms![mainform]!Subspace.SourceObject = "subform1"
Forms![mainform]!text2 = dateadd (“mmmm”,6,date())

How can I add automatically 6 months or 1 year to the actual date from a cmd click.

Hope you understand and that you can help me.

Thanks,

Froggy.
 
If you actually have two subforms, have the expiration field in one subform default to one year from now

=Date()+365

and in the other, default it to 6 months from now

=Date()+182

Do this at the form level (I'm guessing they write to the same table). If you want to remove human error from the equation, you can then lock the field and take it out of the tab order.

HTH
 
Hi Rubbernilly,

I love it it works nicely, I don'y know why we alway try complex thing when it is so simple.

thanks,

Froggy
 
Hi,

youre original code was almost correct :

dim expdate as date

expdate=date
expdat=dateadd ("m", 6, expdate)

only 1 "m
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top