Solved

Setting Date DafaultValue on a form in MS Access

Posted on 2012-03-29
6
318 Views
Last Modified: 2012-05-29
I have a form that pops up when a command button is pressed. The calling form has values I'd like the called form to initiate as Default Values, ie Text1.DefaultValue = Forms!Mainform!MainformValue.

All this seems fine EXCEPT for date values. I have two bound date fields  on the popped form and I'm trying to populate them with dates on the calling form. But all I get is a time format, 12:00:00 AM. There's no formatting  on the called form text box.

I've tried the code to set the date values in the On Open, On Current and On Activate Events. None of them work.

I even try to just set the default value to Date(). Even that didn't work.

No problems with references.


There's no default value in the table. The Text Box doesn't have a default value, till I set it.

I'm not sure what's going on.

Any help would be greatly appreciated.

Thanks,
E
0
Comment
Question by:eantar
6 Comments
 
LVL 39

Expert Comment

by:als315
ID: 37783217
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 37783226
I would generally use the Current event with code similar to:

Private Sub Form_Current

    me.PopupControl1 = cdate(forms!mainform.control1)
    me.popupcontrol2 = cdate(forms!mainform.control2)

End sub

What have you tried.  It might be easier to fix what you have tried than for us to guess on your form and control names.
0
 
LVL 20

Expert Comment

by:clarkscott
ID: 37783243
You could set these values on the OPEN FORM event.

Me.txtDate1 = Date()

or Me.txtDate1 = "1/1/2012"

Scott C
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 5

Accepted Solution

by:
eantar earned 0 total points
ID: 37783616
Hi friends,

I finally got it to work by saving the date values from the calling form into a non visible field and setting the DefaultValue of my visible field to the value of my non visible field.

Anyone have a clue as to why that worked? Why the other way didn't?

Just curious.

E
0
 
LVL 29

Expert Comment

by:IrogSinta
ID: 37785617
I'm wondering if it would work if you put it on the OnLoad event.  I'm not sure what kind of control you're using but I remember once using an ActiveX date control where the default date could only be set on the OnLoad event and not OnOpen.
0
 
LVL 5

Author Closing Comment

by:eantar
ID: 38021302
I resolved this myself
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question