Results 1 to 9 of 9
  1. #1
    Pawtang's Avatar
    Pawtang is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    91

    Default values from table on unbound form

    Yo,

    The purpose of this form is to allow the user to edit the customer info that will populate a generated report before it is created. The form is opened from a specific record, so it opens to a specific customer. Sometimes the user needs to edit some of the information for the specific case of the generated report, so this allows them to modify on the fly without changing the customer's actual stored data.
    Click image for larger version. 

Name:	MTOForm.PNG 
Views:	19 
Size:	9.9 KB 
ID:	45118



    I set the record source of the form to tblCustomers, and the Customer Number box is bound, but all other boxes are unbound. I set their default value to equal (for example) =[company] or =[city], which should refer to the record source's field. As you can see I'm getting these referencing errors. Any ideas why?

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    You cannot reeference a table like that you would need to use dLookup("[City]","[tblCustomer]","[CustomerNumber]='" & [Customerumber] & "'") or a reference to a control on another open form (Forms!frmMainForm!City).

    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Also, textboxes with an expression as the datasource cannot be edited. All the DLookups as described above would have to be in the form's Current event.
    Another option could be a query filtered by Customer Number, containing all the required fields. The query would be the recordsource for the form.
    Then open a dao.recordset based on the query and individually set the textboxes to the appropriate values in the recordset, again in the form's current event.

    In either case, you still have the chore of coding the update of each individual field back to tblCustomers.
    Lotsa trouble. Why not have a bound form?

  4. #4
    Pawtang's Avatar
    Pawtang is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    91
    I want to avoid a bound form because I don't want to change the existing data in the Customer table. For example, sometimes we are just entering a different contact at the same company for the report to be addressed to, but they are not the main contact to be saved for the company - just a one-off contact for the report. Perhaps there's a way to delay updating such that it never actually changes the records?

  5. #5
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    Quote Originally Posted by Pawtang View Post
    I want to avoid a bound form because I don't want to change the existing data in the Customer table. For example, sometimes we are just entering a different contact at the same company for the report to be addressed to, but they are not the main contact to be saved for the company - just a one-off contact for the report. Perhaps there's a way to delay updating such that it never actually changes the records?
    I assume your report is based on a table or query, not values transferred directly from the form to a report (or just printing the form).
    Create a temporary table that contains all the fields required for the report. After the form is updated, empty the table and then have an append query insert all the fields from the form into the temporary table. There's your report recordsource.

  6. #6
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    I think the dLookups in the default value will work as long as you set the Data Entry=Yes to force a new record (or open the form with Docmd.OpenForm with DataMode acFormAdd.
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  7. #7
    Pawtang's Avatar
    Pawtang is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Mar 2021
    Posts
    91
    Quote Originally Posted by davegri View Post
    I assume your report is based on a table or query, not values transferred directly from the form to a report (or just printing the form).
    Create a temporary table that contains all the fields required for the report. After the form is updated, empty the table and then have an append query insert all the fields from the form into the temporary table. There's your report recordsource.
    It originally was just based on customers table, and matching the customer number of the form that launched it. I just started building this intermediary form today, my plan was to spit the form's values out into the report.

    I'm not sure about the temporary table approach; if I'm binding to that spoof table, I won't have the existing customer records to populate the form anyway, unless I use DLookups I guess?

  8. #8
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,413
    I'm not sure about the temporary table approach; if I'm binding to that spoof table, I won't have the existing customer records to populate the form anyway, unless I use DLookups I guess?
    Either method from post #3 will fill the table with the current customer fields.

  9. #9
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,803
    I vote for the temp, or as I call it, a staging table because as soon as you say temp table people start warning you to not do make table queries all the time. That table would have all fields required for the report and get the records from an append query so I don't get that comment about missing fields. This solution eliminates any DLookups and any fields can be altered without affecting the original data. When you're done, you simply dump the staging data.

    You could also just pass a recipient value to the report via report OpenArgs and use it from there.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. default value for unbound control on form
    By Cottonshirt in forum Forms
    Replies: 2
    Last Post: 03-29-2020, 02:10 AM
  2. Unbound Combo on form to show a default value
    By d9pierce1 in forum Forms
    Replies: 11
    Last Post: 04-13-2019, 01:14 PM
  3. Replies: 19
    Last Post: 09-09-2014, 01:36 AM
  4. Replies: 10
    Last Post: 12-24-2013, 12:53 PM
  5. Replies: 5
    Last Post: 03-23-2011, 02:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums