A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Pass Input Text Field From 1 Form to Secondary Form



 
 
Thread Tools Display Modes
  #1  
Old December 14th, 2004, 02:37 PM
Robert Nusz @ DPS
external usenet poster
 
Posts: n/a
Default Pass Input Text Field From 1 Form to Secondary Form

I have an vehicle accident application using two different tables. Table 1 is
primary driver record set. Table 2 would be or could be child record set of
1st, (secondary drivers). I want to be able to create a record type 1 on
entry form, then have command button to "Add Driver" and open 2nd form adding
other driver involved records. I want to save the accident CASE_NUM input on
form 1, and carry that value over to Add Driver form 2 CASE_NUM. I've tried
SetValue and have had no luck, command button works, opens 2nd form, places
focus in proper position, but fails to populate the CASE_NUM field. Any
suggestions would be greatly appreciated.

Bits of Code follows:

Form 1 name is: FR_CR_E
Field name is: Saved_Case_Num
Control Source: = [CASE_NUM]

Form: FR_CR_E has "Add Driver" command button with the following code:
name = Add_Drivers
Caption = &Add Drivers
Tag = Add_Drivers

ON CLICK code is:

Private Sub Add_Drivers_Click()
On Error GoTo Err_Add_Drivers_Click

Dim stDocName As String

strDocName = "Fr_Add_Driver_E"
' Open Fr_Add_Driver_E form in data-entry mode and store CASE_NUM
' the form's OpenArgs property.
DoCmd.OpenForm strDocName, , , , acAdd, , Me!Saved_Case_Num

' give DRIVER_NUM control focus
Forms![Fr_Add_Driver_E]!DRIVER_NUM.SetFocus

Exit_Add_Drivers_Click:
Exit Sub

Err_Add_Drivers_Click:
MsgBox Err.Description
Resume Exit_Add_Drivers_Click

End Sub

2nd form opens and places cursor in proper field, allows entry of new
secondary drivers, but fails to carry over and place the CASE_NUM field from
previous form.
Any suggestions or assistance would be greatly appreciated. Thanks in
advance.

--
Robert Nusz @ DPS
  #2  
Old December 14th, 2004, 03:16 PM
Peter Hammond
external usenet poster
 
Posts: n/a
Default

Hi Robert,

what I usually do in this case is to use the "BeforeInsert" event in the
secondary form.
Something like this:

Private Sub Form_BeforeInsert(Cancel As Integer) 'This is the BeforeInsert
event in the _secondary_ form

[Table2.CaseNum] = Forms![MainForm]![CaseNum]

End Sub

this works provided that you use a Query as the source to the Form.
this is another example using text controls instead of inserting the value
directly on the table field

Private Sub Form_BeforeInsert(Cancel As Integer)
Me.Form2.CaseNum = Forms![MainForm]![CaseNum]
End Sub

of course you would first have to validate that the CaseNum in the primary
form is not null (if your caseNum field in your table2 is a key). I'm sure
there are other ways to do it, but this one works fine for me...

Hope this helps

Peter


 




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

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to clear controls of Filter form Jan Il Using Forms 2 November 28th, 2004 02:04 PM
open a form through a subform in access 2000 Tammy Setting Up & Running Reports 12 October 22nd, 2004 02:43 PM
Display Parameter from Form on Report sara Setting Up & Running Reports 10 July 19th, 2004 04:54 PM
Recordset in subform based on field in parent form Lyn General Discussion 15 June 14th, 2004 03:10 PM
Word 97 and Text Form Field MM General Discussion 1 May 31st, 2004 08:30 AM


All times are GMT +1. The time now is 02:26 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.