![]() |
|
|
#1
|
|||
|
|||
|
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! |
|
#2
|
||||
|
||||
|
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" |
|
#3
|
|||
|
|||
|
Thanks! I will try this. Can you help me with the VBA code that would acomplish this? I'm a newbie.
|
|
#4
|
|||
|
|||
|
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! |
|
#5
|
||||
|
||||
|
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" |
|
#6
|
|||
|
|||
|
My fault. I forgot to bind Form2.SID to the table. The combination of binding and OnLoad code did the trick. Thanks!
|
|
#7
|
||||
|
||||
|
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" |
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
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 |