new form with data from a previous form

Clivej01

Clive
Local time
Today, 19:23
Joined
Dec 18, 2006
Messages
10
I have a Table and a form "a" with a contact ID Field with various fields displaying various information about the names of a business. I want to open another form "b" from the original and input address details about the contact. When the second form "b" opens i need the contact ID field to be copied form "a" to the new form "b".


Back ground on me
I haven't used access in approx 10 years need help to jog the grey matter..
 
Here's a routine that opens a second form (FormB) checks to see if a record with that ID exists, and retrieves that record. If the record doesn't exist, it creates it, inserting the ID from the first form. This will not only allow you to create a new record in the second form, but from the first form, retrieve an existing record on the second form to edit address info if needed.

Just replace all object names with your actual names:

In The calling (first) form

Code:
Private Sub Go2FormB_Click()
If Not IsNull(Me.ContactID) Then
  DoCmd.OpenForm "TableB", , , , , , Me.ContactID
 Else
  MsgBox "A Contact ID Must Be Entered First!"
 End If
End Sub
In the called (second) form

Code:
Private Sub Form_Load()

If Not IsNull(Me.OpenArgs) Then
 Set rst = Me.RecordsetClone
 
[B] rst.FindFirst "[ContactID] = '" & Me.OpenArgs & "'"[/B]

  If Not rst.NoMatch Then
      Me.Bookmark = rst.Bookmark
   Else
    DoCmd.GoToRecord , , acNewRec
    Me.ContactID = Me.OpenArgs
   End If

rst.Close
Set rst = Nothing
End If

End Sub
This code assumes that ContactID is defined as a Text Datatype. If ContactID is defined as a Number, replace

rst.FindFirst "[ContactID] = '" & Me.OpenArgs & "'"

with

rst.FindFirst "[ContactID] = " & Me.OpenArgs
 
Table "tbla" "tblcntcmpynme"
Field "flda" "cmpynmeid" Long Integer
Form "frma" "frmCntCmpyNme"

Table "tblb" "tblCntCmpylctn"
Field "fldb "cmpynmeid" Long Integer
Form "frmb" "frmCntCmpylctn"


frma is already loaded with data displayed and I need to Load Frmb and put the value from cmpynmeid in frma in the cmpynmeid of frmB

could you fill in the previous attached code with the correct names or could you please annotate the code for me to learn ie

Put table name here etc.

If you could do both it would be much appreciated.

Clive

PS there always more than one way to skin a cat

PPS but ask the cat, the outcome is always the same.
 

Users who are viewing this thread

Back
Top Bottom