Microsoft Access Forums

Go Back   Microsoft Access Forums > Access Forums > Forms

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 02-06-2010, 10:34 AM
Bruce Bruce is offline Windows XP Access 2003 (version 11.0)
Advanced Beginner
 
Join Date: Nov 2009
Posts: 38
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, 12:32 PM
RuralGuy's Avatar
RuralGuy RuralGuy is online now Windows 7 Access 2007 (version 12.0)
Super Moderator
 
Join Date: Mar 2007
Location: 8300' in the Colorado Rocky Mountains
Posts: 3,433
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, 08:03 AM
Bruce Bruce is offline Windows XP Access 2003 (version 11.0)
Advanced Beginner
 
Join Date: Nov 2009
Posts: 38
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, 10:57 AM
Bruce Bruce is offline Windows XP Access 2003 (version 11.0)
Advanced Beginner
 
Join Date: Nov 2009
Posts: 38
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, 01:14 PM
RuralGuy's Avatar
RuralGuy RuralGuy is online now Windows 7 Access 2007 (version 12.0)
Super Moderator
 
Join Date: Mar 2007
Location: 8300' in the Colorado Rocky Mountains
Posts: 3,433
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, 02:09 PM
Bruce Bruce is offline Windows XP Access 2003 (version 11.0)
Advanced Beginner
 
Join Date: Nov 2009
Posts: 38
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, 04:05 PM
RuralGuy's Avatar
RuralGuy RuralGuy is online now Windows 7 Access 2007 (version 12.0)
Super Moderator
 
Join Date: Mar 2007
Location: 8300' in the Colorado Rocky Mountains
Posts: 3,433
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
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 On
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 01:15 AM
Pass a Parameter From a form to a Query DDillesha Forms 1 10-28-2009 11:49 AM
I want to automatically pass a value to a query Slategrey252 Queries 1 10-01-2009 04:38 AM
90 days in the pass - Date help wanted techexpressinc Queries 1 01-26-2009 05:13 AM
Updating Multiple Pass-Through Queries through a Form ryan05 Access 0 03-19-2006 09:52 PM


All times are GMT -8. The time now is 06:15 PM.


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