![]() |
|
|
#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" |
|
#8
|
|||
|
|||
|
I have same prob. and am Newbe please can you send me code and more explanation
many thanx |
|
#9
|
||||
|
||||
|
Quote:
__________________
(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" |
|
#10
|
|||
|
|||
|
Quote:
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 |
|
#11
|
||||
|
||||
|
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" |
|
#12
|
|||
|
|||
|
Many thanks
do I put th ecode under form load or after update |
|
#13
|
||||
|
||||
|
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" |
|
#14
|
|||
|
|||
|
It passed the value but doesnt save it in tables
thanks alot |
|
#15
|
|||
|
|||
|
Quote:
thanx |
|
| 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 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 |