Solved

Setting Date DafaultValue on a form in MS Access

Posted on 2012-03-29
6
310 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
Comment Utility
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
Comment Utility
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
Comment Utility
You could set these values on the OPEN FORM event.

Me.txtDate1 = Date()

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

Scott C
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 5

Accepted Solution

by:
eantar earned 0 total points
Comment Utility
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
Comment Utility
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
Comment Utility
I resolved this myself
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

763 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

11 Experts available now in Live!

Get 1:1 Help Now