Share via

access 2010: TempVars Use

Anonymous
2012-07-09T21:21:26+00:00

I started with the Contacts Web Database template to create a database to create and track work orders for a database.

Using the basic structure, I can open the form ContactDetail for each contact.  On the form ContactDetail I have a subform that shows all the work orders for the contact.  I now want to create a button on the Contact Detail form that opens a new work order for that contact.  I can easily create a command that will open the form WorkOrder as a blank form.  My goal now is to the new work order open with the ID field already populated.

ID is the common field between Contacts, ContactDetails, and WorkOrder.

Is this accomplished through a TempVar?

I appreciate your time in answering this question.  I'm not sure what information you need to provide the solution.

Microsoft 365 and Office | Access | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

30 answers

Sort by: Most helpful
  1. Anonymous
    2012-07-12T05:57:25+00:00

    Laurel-

    You said "ID is the common field," so that's the way I put it in the code.  Yes, if it's CustomerID on the WorkOrder form, then you have to use that in the macro.

    If Not IsNull([TempVars]![IDValue]) Then

    SetProperty

    Control Name:  CustomerID

    Property:        Value

    Value:  TempVars!IDValue

    End If

    John Viescas, author

    Microsoft Office Access 2010 Inside Out Microsoft Office Access 2007 Inside Out Building Microsoft Access Applications Microsoft Office Access 2003 Inside Out SQL Queries for Mere Mortals http://www.viescas.com/

    (Paris, France)

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2012-07-12T00:32:07+00:00

    Thank you.  I feel very fortunate to have the actual author of Inside Out helping me. This is exactly the type of how-to explanation I needed. I really like that you explained why I was doing these steps, as well.

    I put the information for the macro and there weren't any error messages.

    When I pulled up the WorkOrder form and went to On Load the macro was rejected.

    "The control name 'ID' is misspelled or refers to a control that doesn't exist."...

    Is this because on the WorkOrder, the field I need populated is called [CustomerID]?

    I wish I could provide screen shots to help the explanation.

    Thank you for your time.

    Laurel

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2012-07-11T07:24:04+00:00

    Your macro to open the form should look like:

    SetTempVar

    Name:  IDValue

    Expression =  [ID]

    OpenForm

    Form Name:  WorkOrder

    DataMode:      Add

    WindowMode:   Dialog


    Then in the Load event of WorkOrder, do:

    If Not IsNull([TempVars]![IDValue]) Then

    SetProperty

    Control Name:  ID

    Property:        Value

    Value:  TempVars!IDValue

    Basically, you're saving the current value of ID in a TempVar that you create, then you check it in the Load event of the form and set the ID if the TempVar has a value.

    Let me know if that's not clear enough.

    John Viescas, author

    Microsoft Office Access 2010 Inside Out Microsoft Office Access 2007 Inside Out Building Microsoft Access Applications Microsoft Office Access 2003 Inside Out SQL Queries for Mere Mortals http://www.viescas.com/

    (Paris, France)

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2012-07-11T03:09:09+00:00

    Thank you for the quick response.  I'm very limited in my programming skills.  I'm not quite sure how to do what you suggested.

    I when I go "on click" and create the embedded macro, so far I have

    OpenForm

    FormName >WorkOrder

    DataMode>Add

    WindowMode>Dialog

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2012-07-10T17:04:03+00:00

    Laurel-

    Yes, a TempVar might do the trick.  Just before you open the form, save the current ID in a TempVar.  Then in the Load event of the new form, grab the TempVar and set either the ID in the form or the DefaultValue (SetProperty) of the ID field.

    John Viescas, author

    Microsoft Office Access 2010 Inside Out Microsoft Office Access 2007 Inside Out Building Microsoft Access Applications Microsoft Office Access 2003 Inside Out SQL Queries for Mere Mortals http://www.viescas.com/

    (Paris, France)

    Was this answer helpful?

    0 comments No comments