Solved

Looking for advise on how to overwrite a default value

Posted on 2014-01-16
1
379 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
ID: 39785458
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

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.

Question has a verified solution.

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

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…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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…

910 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

24 Experts available now in Live!

Get 1:1 Help Now