Today's guest writer is Sue Schaefer from Support Training. She recently wrote a helpful article about how the List Item Edit form works with OpenArgs. The new-to-Access 2007 List Items Edit Form property of a Lookup field allows you to pass the value of new data into the form you enter as the property. Take a look at the Owner field in the Assets table in the Assets database template. The Allow Value List Edits property is set to Yes and the List Items Edit Form is set to Contact Details. When you open the Asset List form and enter a new Owner in the Owner field, you are asked if you want to add a new value to the list. If you click yes,
Office 2010 Key, the value you entered is passed to the OpenArgs property of the Contact Details form. The OnLoad event of the Contact Details form contains an embedded macro that looks for the OpenArgs property. When the database is in a trusted state,
Genuine Office 2010, the embedded macro takes the new data that is now in the OpenArgs property and passes it to the Last Name and First Name fields in the Contact Details form. The embedded macro parses the new data into First Name and Last Name and displays it on the Contact Details form so that that you don;t have to retype the name(s) you already typed in the Owner field. If the database is not trusted, the macro stops and you have to manually enter the new data on the Contact Details form. The following table is a step-by-step explanation of the Contact Details OnLoad macro actions. Macro Action Explanation Stop Macro If nothing is in the OpenArgs property because the user has not clicked Yes to add new data to the Owner dropdown,
Office Professional 2007 Key, the macro stops. GoToRecord Navigates the Contact Details form to a New record. StopMacro If the database is not in a trusted state, stop the macro and let the user enter the data in the Contact Details form. SetTempVar If the database is trusted, this creates the TempVars variable, NewData to hold the information passed when you clicked Yes to add new data. The Mid() function removes the data prior to the =sign in the OpenArgs value. The full OpenArgs value passed would be: [Asset List],
Office 2007 Enterprise Key![Owner]=
SetTempVar Creates the Space variable to hold the position of any spaces it finds in the NewData variable. OnError Goes to the next command if an error occurs SetValue If no space in the NewData variable and NewData is not an empty string,Purchase Office 2010, put the data in NewData into the Last Name field. SetValue If there is a space in NewData, put the data to the left of the Space in the First Name field. SetValue If there is a space in NewData, put the data after the space in the Last Name field Remove TempVar Clear the NewData variable Remove TempVar Clear the Space variable You will notice the macro is written slightly different when the lookup is something like a company (see the Customer Service template). It gets simpler because you don't have to try and parse the first and last name.