Solved

Opening new form to New item but passing some specific data

Posted on 2011-02-21
3
228 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

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…
It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

762 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

20 Experts available now in Live!

Get 1:1 Help Now