Solved

Opening new form to New item but passing some specific data

Posted on 2011-02-21
3
229 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
  • 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 19

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 19

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now