Solved

Looking for advise on how to overwrite a default value

Posted on 2014-01-16
1
382 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

749 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