Solved

Opening new form to New item but passing some specific data

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Familiarize people with the process of utilizing SQL Server functions 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 Microsoft Ac…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

777 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