Solved

Setting Date DafaultValue on a form in MS Access

Posted on 2012-03-29
6
316 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

867 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now