?
Solved

Opening new form to New item but passing some specific data

Posted on 2011-02-21
3
Medium Priority
?
234 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 500 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

770 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