473,395 Members | 1,688 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to pass a field-value in one form to a field in another form.

kobamfo
14
Hello Guys,
I have two forms "in_lookup" and "in_main" and I have a field in "in_lookup" named "snl_lk" and a field in "in_main" named "snl_in".
I want a value entered in "snl_lk" in "in_lookup" form to automatically fill "snl_in" in "in_main" upon click of an "accept" button on "in_lookup" form, then a "cancel" button on the same form would simply close the "in_lookup" form.
Note that it is assumed that both forms are open by the user.

I am at my wit's end. please
Nov 5 '12 #1
5 5509
zmbd
5,501 Expert Mod 4TB
please post your code...
Remember to format it with the <CODE/> button.
there are at least 6 ways off the top of my head to do this and the best one depends on what you've already done.
Nov 5 '12 #2
TheSmileyCoder
2,322 Expert Mod 2GB
I presume your lookup form is opened by the use of a button, or click somewhere. The important thing is that it is opened as a dialog.
Expand|Select|Wrap|Line Numbers
  1. Private Sub btn_LookupValue_Click()
  2.   docmd.OpenForm "in_lookup",,,,,acDialog
  3. End Sub
Now whenever the user has selected the value he/she wants, I again presume there is a button to close the form.
Expand|Select|Wrap|Line Numbers
  1. Private Sub btn_Close()
  2.   'Hide the form, don't cloes it yet
  3.   Me.Visible=False
  4. End Sub
Now as the form is hidden, this causes control to return to the calling code. So we modify the the first bit of code I posted:
Expand|Select|Wrap|Line Numbers
  1. Private Sub btn_LookupValue_Click()
  2.   docmd.OpenForm "in_lookup",,,,,acDialog
  3.  
  4.   'Note the following lines only execute AFTER the lookup form is set to not visible
  5.   Me.snl_in=Forms("in_lookup")!snl_lk
  6.  
  7.   'Now that we have the value we no longer need the form, so close it
  8.   Docmd.Close acForm,"in_lookup"
  9. End Sub
As ZMBD correctly stated there are many many different ways to do this, and the correct approach depends on your EXACT requirements.
Nov 5 '12 #3
NeoPa
32,556 Expert Mod 16PB
The code behind the [Accept] button could populate the control using references explained in Referring to Items on a Sub-Form.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Accept_Click()
  2.     Forms("in_main").snl_in = Me.snl_lk
  3. End Sub
I leave you to determine how much sense this code makes, but I believe it answers the question as asked.
Nov 5 '12 #4
kobamfo
14
Good news!
TheSmileyCoder, I tried out your approach and NeoPa I also tried your straight to the point approach and all worked just as I wanted, but I guess I found a mid-point and here is the code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Accept_Click()
  2. If IsNull(snc_dl.Value) Then
  3. Dim Msg, Style, Title, MyString
  4. Msg = "You have not entered a Serial Number for a Lookup"
  5. Style = vbOK
  6. Title = "Missing Data"
  7. response = MsgBox(Msg, Style, Title)
  8. If response = vbOK Then
  9.     snc_dl.SetFocus
  10.     End If
  11. End If
  12. If Not IsNull(snc_dl.Value) Then
  13.     Forms("pre_entry").snc_pre = Me.snc_dl
  14.     DoCmd.close acForm, "out_subform"
  15. End If
  16. End Sub
The code above is on the On_Click Event Procedure of the close button on the "sub-form" (out_subform) so to speak, even though its not really a sub form.
The out_subform actually performs a DlookUp based on an "snc_dl" value. The idea is that if the user is okay with the DlookUp result, they accept the "snc_dl" value which is passed on to a field named "snc_pre" in the "pre_entry" form. The main form so to speak. I hope I have been able to communicate my little idea. :-)
But I really appreciate your help by putting me in the right direction. Thanks!!!
Nov 7 '12 #5
TheSmileyCoder
2,322 Expert Mod 2GB
Thats good to hear. Remember that most code posted are concept code, that does not take into account such issues as null/empty controls.

I myself have found it simpler to post concept code and leave it to the original poster to convert it to functional code. It tends to clutter up the message if I include too much info.

You have clearly taken the correct approach in not simply doing Copy/Paste, but trying to understand the concept, and then implement it with the proper checks. Looking forward to more posts from you.

Best of luck with your project.
Nov 7 '12 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

110
by: Mr A | last post by:
Hi! I've been thinking about passing parameteras using references instead of pointers in order to emphasize that the parameter must be an object. Exemple: void func(Objec& object); //object...
0
by: uli2003wien | last post by:
Dear group, PASS (SQL-Server user group) is about to start founding a branch in Vienna. I went to SQLCON and met some guys from the German PASS group and decided to become a member of PASS,...
8
by: Tcs | last post by:
I've been stumped on this for quite a while. I don't know if it's so simple that I just can't see it, or it's really possible. (Obviously, I HOPE it IS possible.) I'm trying to get my queries...
2
by: Robert | last post by:
when using the following function to create a pass through query is there a way to set the query property, "Returns Rows" to no. The default is yes. Since we are planning to create the pass...
7
by: Zlatko Matić | last post by:
Let's assume that we have a database on some SQL server (let it be MS SQL Server) and that we want to execute some parameterized query as a pass.through query. How can we pass parameters to the...
9
by: Jay Douglas | last post by:
Hello, I am needing to pass a class object (this) by reference to a method in a different class. When I do the following code I get the error (Cannot pass '<this>' as a ref or out argument because...
2
by: Alex Nitulescu | last post by:
Hi. I have tried to pass two parameters, like this: Response.Redirect(String.Format("NewPage.aspx?Username={0}, Pass={1}", txtUserName.Text, txtPass.Text)) But if I pass Username="Alex" and...
1
by: Greg Strong | last post by:
Hello All, Why would brackets be added to the SQL of a pass through query to Oracle? If I paste the debug print of the SQL statement into SQLPlus of Oracle's XE edition it works, and does NOT...
15
by: ramif | last post by:
Does call by reference principle apply to pointers?? Is there a way to pass pointers (by reference) to functions? Here is my code: #include <stdio.h> #include <stdlib.h>
5
by: marshmallowww | last post by:
I have an Access 2000 mde application which uses ADO and pass through queries to communicate with SQL Server 7, 2000 or 2005. Some of my customers, especially those with SQL Server 2005, have had...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.