Solved

Setting default values for a new record

Posted on 2011-09-10
7
351 Views
Last Modified: 2013-11-27
Great Day, I am creating a job order for an automotive repair shop. When I open an estimate to review it, all of the data has populated the form properly; however, when I create a new estimate, customer name and address and customer vehicle make, model and year, I expected to automatically populate the appropriate fields, but they did not.

Do I need to code the default value for those fields or is there a way for access to automatically do it when a new record is detected?

Thanks in advance,

David
0
Comment
Question by:yddadsjd95
[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
  • 4
  • 3
7 Comments
 

Author Comment

by:yddadsjd95
ID: 36516290
Okay, I've discovered that since I am at a new record, the customer data that I was expecting to be able to load, is not available on the form, so I'll have to get it elsewhere. I suspect that I can pull it from the form that loaded the Job Order, so I'll play with it and give you an update.
0
 

Author Comment

by:yddadsjd95
ID: 36516367
I am unable to get a default value to load when the form opens to a new record. This is the code that I used to test one field

If Me.NewRecord Then
        'Set the defaults
        Forms!FrmJob!frmJobSub.Form!txtStreetAddress.DefaultValue = " Forms!   frmCustomerContactData!StreetAddress" _

End If

I am attempting to use the data that is in the form (frmCustomerContactData) that opened the Estimate/Work Order (frmJobOrder). When I check the Immediate Window, there is a value for txtStreetAddress; however, nothing loads on the form when it opens.

Thanks in advance for your assistance.

r/David

If Me.NewRecord Then
        'Set the defaults
        Forms!FrmJob!frmJobSub.Form!txtStreetAddress.DefaultValue = " Forms!   frmCustomerContactData!StreetAddress" _

End If

Open in new window

0
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 500 total points
ID: 36516659
First, lets clear up the terminology....

Technically, a default value is a value that is always there when a New record is created.
(See the help files on "Default Value")

(It can be made to be a "default value" in other circumstances, but this is another discussion)


For example, if 95% of all of your customers will be form Nevada, then "Navada" could be the default value for the "State".

Creating a new work order for the same customer merely requires you to save the CustomerID.
(a strict "default value" is not heeded here)

When the WorkOrder for the existing customer is displayed on the form, simply do something roughly like this in the Form's declaration section:

Private lngpvtCustID As Long

Then, on a button called "New Work Order for existing Customer" put code like this:

    'Store the custID in the
    lngpvtCustID = Me.CustomerID
    DoCmd.GoToRecord , , acNewRec

Finally on the current event of the form do something like this:

'If new record and there is a customer selected
If Me.NewRecord And Not IsNull(lngpvtCustID) Then
    'Look up the cust fields
    Me.txtCustName = DLookup("CustName", "CustomerTable", "CustID=" & lngpvtCustID)
    Me.txtCustAddress = DLookup("CustName", "CustomerTable", "CustID=" & lngpvtCustID)
    '...etc
    'Save these entries
    DoCmd.RunCommand acCmdSaveRecord
    'Clear the variable
    lngpvtCustID = Null
end if


I am sure that based on your experience here you can get this working in your database...


JeffCoachman
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 74

Assisted Solution

by:Jeffrey Coachman
Jeffrey Coachman earned 500 total points
ID: 36516670
...small tweak:

'If new record and there is a customer selected
If Me.NewRecord And Not IsNull(lngpvtCustID) Then
    me.txtCustID=lngpvtCustID
    'Look up the cust fields
    Me.txtCustName = DLookup("CustName", "CustomerTable", "CustID=" & lngpvtCustID)
    Me.txtCustAddress = DLookup("CustName", "CustomerTable", "CustID=" & lngpvtCustID)
    '...etc
    'Save these entries
    DoCmd.RunCommand acCmdSaveRecord
    'Clear the variable
    lngpvtCustID = Null
end if

0
 

Author Comment

by:yddadsjd95
ID: 36516941
Thanks Jeff, I'm working on it.
0
 

Author Closing Comment

by:yddadsjd95
ID: 36522793
Thank you Jeff, I worked on this for quite some time before I was able to get it to work. Thanks a million. However, now I am running into another issue where when I open the form Access is asking for a parameter, which I will address under a new question.

Have a great day and an even finer day tomorrow.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 36524176
ok
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
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.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

738 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