Microsoft Access Forums

Go Back   Microsoft Access Forums > Access Forums > Forms

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 02-06-2010, 09:34 AM
Bruce Bruce is offline Windows XP Access 2003 (version 11.0)
Advanced Beginner
 
Join Date: Nov 2009
Posts: 49
Bruce is on a distinguished road
Default Pass data from one form to another

I have two tables (Table1 and Table2) and I use forms to enter data. There is a numeric field in the first and second form named SID. I have set the data control source on the second form (Form2) SID field to =Forms!Form1!SID. After completing data entry on Form1, I use a command button to open Form2 and the SID field data from Form1 is automatically entered in the SID field in Form2. However, after filling out the remaining data on Form2 and exiting the forms, I check the data in Table2 and the SID value is not being saved. The other data that was entered is saved but the SID number pulled from Form1 shows up as "0" in the table. I also tried modifying the code on the OpenForm event with OpenArgs but that didn't work either.

I suspect this is a common use for passing a primary key value from Table1 to Table2 (foreign key). Eventually I'll hide the fields but I need to know why the numeric value transferred is not being saved in the table.

Im using Access 2003. Thanks!
Reply With Quote
  #2  
Old 02-06-2010, 11:32 AM
RuralGuy's Avatar
RuralGuy RuralGuy is online now Windows 7 Access 2007 (version 12.0)
Administrator
 
Join Date: Mar 2007
Location: 8300' in the Colorado Rocky Mountains
Posts: 4,263
RuralGuy will become famous soon enoughRuralGuy will become famous soon enough
Default

You have a calculation as the ControlSource of your control in Form2. You should bind the control to the field you want to update (the FK field). The Open event is too early in the process to reference a control on a form; you need to use the OnLoad event. Then you could use the OpenArgs or the Forms collection to set the value of the Form2Control and it will save. Me.SID = Forms!Form1!SID
__________________
(RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 - acXP, ac07
If your issue is resolved...follow this link for directions on how to use the Solved thread tool!
Teaching is not filling a bucket but lighting a fire. Borrowed quote..."Docendo discimus"
Reply With Quote
  #3  
Old 02-08-2010, 07:03 AM
Bruce Bruce is offline Windows XP Access 2003 (version 11.0)
Advanced Beginner
 
Join Date: Nov 2009
Posts: 49
Bruce is on a distinguished road
Default

Thanks! I will try this. Can you help me with the VBA code that would acomplish this? I'm a newbie.
Reply With Quote
  #4  
Old 02-08-2010, 09:57 AM
Bruce Bruce is offline Windows XP Access 2003 (version 11.0)
Advanced Beginner
 
Join Date: Nov 2009
Posts: 49
Bruce is on a distinguished road
Default

I added the following code to the OnLoad event of Form2:

Me.SID = Forms![Form1]![SID]

The number was imported correctly but STILL not saved to Table2. I've checked for any restrictions but can find nothing that would stop this number from being saved to the table. bummer!

Appreciate any other troubleshooting tips or suggestions. Thanks!
Reply With Quote
  #5  
Old 02-08-2010, 12:14 PM
RuralGuy's Avatar
RuralGuy RuralGuy is online now Windows 7 Access 2007 (version 12.0)
Administrator
 
Join Date: Mar 2007
Location: 8300' in the Colorado Rocky Mountains
Posts: 4,263
RuralGuy will become famous soon enoughRuralGuy will become famous soon enough
Default

Do you have a control on your form named SID? If so, rename it to txtSID. Is the same control bound to the SID field of the RecordSource of the form? Then change your code to: Me.txtSID = Forms![Form1]![SID]
__________________
(RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 - acXP, ac07
If your issue is resolved...follow this link for directions on how to use the Solved thread tool!
Teaching is not filling a bucket but lighting a fire. Borrowed quote..."Docendo discimus"
Reply With Quote
  #6  
Old 02-08-2010, 01:09 PM
Bruce Bruce is offline Windows XP Access 2003 (version 11.0)
Advanced Beginner
 
Join Date: Nov 2009
Posts: 49
Bruce is on a distinguished road
Smile

My fault. I forgot to bind Form2.SID to the table. The combination of binding and OnLoad code did the trick. Thanks!
Reply With Quote
  #7  
Old 02-08-2010, 03:05 PM
RuralGuy's Avatar
RuralGuy RuralGuy is online now Windows 7 Access 2007 (version 12.0)
Administrator
 
Join Date: Mar 2007
Location: 8300' in the Colorado Rocky Mountains
Posts: 4,263
RuralGuy will become famous soon enoughRuralGuy will become famous soon enough
Default

You're welcome. Glad I could help.
__________________
(RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 - acXP, ac07
If your issue is resolved...follow this link for directions on how to use the Solved thread tool!
Teaching is not filling a bucket but lighting a fire. Borrowed quote..."Docendo discimus"
Reply With Quote
  #8  
Old 08-06-2010, 03:00 PM
rayan2002 rayan2002 is offline Windows Vista Access 2003 (version 11.0)
Novice
 
Join Date: Jul 2010
Posts: 5
rayan2002 is on a distinguished road
Default

Quote:
Originally Posted by RuralGuy View Post
You're welcome. Glad I could help.
I have same prob. and am Newbe please can you send me code and more explanation
many thanx
Reply With Quote
  #9  
Old 08-06-2010, 03:49 PM
RuralGuy's Avatar
RuralGuy RuralGuy is online now Windows 7 Access 2007 (version 12.0)
Administrator
 
Join Date: Mar 2007
Location: 8300' in the Colorado Rocky Mountains
Posts: 4,263
RuralGuy will become famous soon enoughRuralGuy will become famous soon enough
Default

Quote:
Originally Posted by rayan2002 View Post
I have same prob. and am Newbe please can you send me code and more explanation
many thanx
Maybe this link will help: http://www.baldyweb.com/OpenArgs.htm
__________________
(RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 - acXP, ac07
If your issue is resolved...follow this link for directions on how to use the Solved thread tool!
Teaching is not filling a bucket but lighting a fire. Borrowed quote..."Docendo discimus"
Reply With Quote
  #10  
Old 08-07-2010, 02:29 PM
rayan2002 rayan2002 is offline Windows Vista Access 2003 (version 11.0)
Novice
 
Join Date: Jul 2010
Posts: 5
rayan2002 is on a distinguished road
Default

Quote:
Originally Posted by RuralGuy View Post
Maybe this link will help: http://www.baldyweb.com/OpenArgs.htm
Thank you very much sir for quick response
but my prob not solve bu this code, I have application (two forms and 2 tables ) the NI is primary key in first form and foriegn key in second form after filling first form1 there is button called Next to fill another part or form 2 user need to write NI manualy . I coul pass the value from form 1 to form 2 but un fortunatly I coudnt save the value in tables . I want NI textbox field passed automatically to NI_card textbox and saved in table
thanx again
Reply With Quote
  #11  
Old 08-07-2010, 02:38 PM
RuralGuy's Avatar
RuralGuy RuralGuy is online now Windows 7 Access 2007 (version 12.0)
Administrator
 
Join Date: Mar 2007
Location: 8300' in the Colorado Rocky Mountains
Posts: 4,263
RuralGuy will become famous soon enoughRuralGuy will become famous soon enough
Default

You can do that with the code from the link I provided.
__________________
(RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 - acXP, ac07
If your issue is resolved...follow this link for directions on how to use the Solved thread tool!
Teaching is not filling a bucket but lighting a fire. Borrowed quote..."Docendo discimus"
Reply With Quote
  #12  
Old 08-09-2010, 11:58 PM
rayan2002 rayan2002 is offline Windows Vista Access 2003 (version 11.0)
Novice
 
Join Date: Jul 2010
Posts: 5
rayan2002 is on a distinguished road
Default

Quote:
Originally Posted by RuralGuy View Post
You can do that with the code from the link I provided.
Many thanks
do I put th ecode under form load or after update
Reply With Quote
  #13  
Old 08-10-2010, 05:52 AM
RuralGuy's Avatar
RuralGuy RuralGuy is online now Windows 7 Access 2007 (version 12.0)
Administrator
 
Join Date: Mar 2007
Location: 8300' in the Colorado Rocky Mountains
Posts: 4,263
RuralGuy will become famous soon enoughRuralGuy will become famous soon enough
Default

As the link shows it goes in the OnLoad event.
__________________
(RG for short) aka Allan Bunch MS Access MVP - WinXP Pro, Win7 - acXP, ac07
If your issue is resolved...follow this link for directions on how to use the Solved thread tool!
Teaching is not filling a bucket but lighting a fire. Borrowed quote..."Docendo discimus"
Reply With Quote
  #14  
Old 08-20-2010, 01:53 AM
rayan2002 rayan2002 is offline Windows Vista Access 2003 (version 11.0)
Novice
 
Join Date: Jul 2010
Posts: 5
rayan2002 is on a distinguished road
Default

It passed the value but doesnt save it in tables
thanks alot
Reply With Quote
  #15  
Old 08-20-2010, 02:09 AM
rayan2002 rayan2002 is offline Windows Vista Access 2003 (version 11.0)
Novice
 
Join Date: Jul 2010
Posts: 5
rayan2002 is on a distinguished road
Default

Quote:
Originally Posted by Bruce View Post
My fault. I forgot to bind Form2.SID to the table. The combination of binding and OnLoad code did the trick. Thanks!
how do you solve the prob can you send me code
thanx
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pass list as parameter to in operator bliever Queries 5 11-11-2009 12:15 AM
Pass a Parameter From a form to a Query DDillesha Forms 1 10-28-2009 10:49 AM
I want to automatically pass a value to a query Slategrey252 Queries 1 10-01-2009 03:38 AM
90 days in the pass - Date help wanted techexpressinc Queries 1 01-26-2009 04:13 AM
Updating Multiple Pass-Through Queries through a Form ryan05 Access 0 03-19-2006 08:52 PM


All times are GMT -8. The time now is 02:40 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.