Solved

Opening new form to New item but passing some specific data

Posted on 2011-02-21
3
232 Views
Last Modified: 2012-05-11

I want to open a form to a new record, but pass some specific data to the form so it is  pre filled out.   For example

On form A, we have a main form with CustomerCode, CustomerName, and some customer specific details from the tabel CUSTOMERS
On this form is a subform called CustomerNotes.  This has CustomerLink (linked to CustomerCode), the Notes_ID (autonumber) and various items from the Customers_Notes table.

From the subform the client can click the Note_ID and goto a viewing screen of that specific note. This works perfectly.
If the client clicks (new) in the Notes_ID then it takes them to a form to enter a new customer Notes record.  I have this working too. However, I would like to pre-fill in the CustomerCode this new note relates to so the client does not have to do it, and eliminate mistakes by the client when doing this.

I am struggling with the very last bit, which is entering the customerCode and CustomerName.  
I have tried setting CustomerCode to the value on the previous form in the following ways

1. As an Openargs value being sent on the docmd.openform when opening Form B for the value of CustomerCode on form A
2. setting the value in form B to the value in form A on both the OnLoad and onOpen events but can't quite get this to work  

My question is what order do events occur ? How can I open the Notes_ID to new record then set customerCode to a specific number, and populate CustomerName based on this CustomerCode, all before the form is visible to the client.

Regards

Ian

Thanks in advance

Ian
0
Comment
Question by:ianLMurdoch
[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
  • 2
3 Comments
 
LVL 15

Expert Comment

by:Simon Ball
ID: 34941637
docmd.openform "newformname" acnew

forms!newformname!fieldname.value = forms!OLDformname!fieldname.value
0
 
LVL 20

Accepted Solution

by:
darbid73 earned 125 total points
ID: 34941665
There are many variations of answers to your question.

I am of the opinion that your openargs is the intended way to pass strings or information from one for to another, thus I am suggesting you do it this way.

1. I suggest your calling code on Form a looks something like this

DoCmd.OpenForm "FORM_B", acNormal, , , , acHidden, str_OpenArgs
    DoCmd.Close acForm, "FORM_Q"
    Forms("FORM_B").Visible = True

Open in new window


This way all of the FORM_B "opening stuff" has to happen before you close your current form.


2. My openargs string is always divided with the ";" symbol.  In the OPEN event of the form being opened I deal with this.  You could also deal with this in an array but I do not change things so I have left it like this.

If Len(Nz(Me.OpenArgs, "")) > 0 Then
    str_firstitem = split(Me.OpenArgs, ";")(0)
    str_seconditem = split(Me.OpenArgs, ";")(1)
    bln_thriditem = split(Me.OpenArgs, ";")(2)
    bln_fourthitem = split(Me.OpenArgs, ";")(3)
End If

Open in new window



I hope this helps


0
 
LVL 20

Expert Comment

by:darbid73
ID: 34941690
My comment did not address a new record.  i choose to do this on the form in question and not in calling it as I usually have forms which do both current records and you can add a new. If that is the case then you use code like this.

The existance of something in your openargs will tip Form B to the fact tht this code needs to be called.


DoCmd.GoToRecord , , acNewRec

Open in new window

0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

724 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