Solved

Looking for advise on how to overwrite a default value

Posted on 2014-01-16
1
375 Views
Last Modified: 2014-01-16
On a form I have a field named "txtGrowDaysEarly".  The form is bound to a table named tblPlantings

The field gets a value when the form opens from an onopen event with:

Me.txtGrowDaysEarly = DLookup("GrowDaysEarly", "tblCatalog", "PlantedID = " & [Forms]![frmPlanted]![txtPlantedID])

But I want to be able to overwrite the value (which is a number) if I want to do so and have that value written to the field named GrowDaysEarly in the table tblPlantings.

But every time the form opens of course it gets the value again from tblCatalog.

I tried NOT putting the code in the onopen event and instead have it in the default value of the field property  but when the form opens it doesn't populate that default value.

Here is the code I have in the default value:

=DLookUp("GrowDaysEarly","tblCatalog","Mnumber = [txtMnumber]")

Mnumber is a number field and is the key field on tblCatalog.

????
0
Comment
Question by:SteveL13
1 Comment
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
Comment Utility
Check the value of Me.txtGrowDaysEarly first:

If Nz(Me.txtGrowDaysEarly,"") = "" Then
  Me.txtGrowDaysEarly = DLookup("GrowDaysEarly", "tblCatalog", "PlantedID = " & [Forms]![frmPlanted]![txtPlantedID])
End If

Open in new window


Or only set this value if the record is new. In the form's Current event:

If Me.NewRecord Then
  Me.txtGrowDaysEarly = DLookup("GrowDaysEarly", "tblCatalog", "PlantedID = " & [Forms]![frmPlanted]![txtPlantedID])
End If

Open in new window

0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

771 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

15 Experts available now in Live!

Get 1:1 Help Now