Transferring id numbers from one form to another (1 Viewer)

Lindsay

New member
Local time
Today, 14:05
Joined
Oct 3, 2011
Messages
1
Hey, I'm new to access.

I have a bunch of forms that are connected to one form called event. The event form has a control called event id. The other forms are deliverables (ie communications resources, demonstrations sites, outreach activities etc). These forms pop up automatically (via an open form macro) when a deliverable type is selected on the events form. All of the deliverable forms have a control called event id. What I am trying to do is populate the event id controls on the other forms automatically when the forms pop up.

I have no experience in writing VBA code so if that is where this is going, please be very specific.

Thank-you for any assistance you can provide.

Lindsay
 

missinglinq

AWF VIP
Local time
Today, 17:05
Joined
Jun 20, 2003
Messages
6,423
I think this kind of thing is going to have to be done thru VBA code, rather than with Macros, because of your need to pass the ID number. Here's two examples, the first one looks to see if there is a matching ID in the form being opened, and if so, displays it. If no match is found, it opens a New Record and populates the ID field with the passed ID.

In The calling form, for both options
Code:
Private Sub Go2SecondForm_Click()
If Not IsNull(Me.EventsID) Then
  DoCmd.OpenForm "SecondForm", , , , , , Me. EventsID Else
  MsgBox "A Events ID Must Be Entered First!"
 End If
End Sub
In the called form, for existing or new record
Code:
Private Sub Form_Load()

Dim rst As Recordset

If Not IsNull(Me.OpenArgs) Then
 Set rst = Me.RecordsetClone
 
 rst.FindFirst "[ EventsID] = '" & Me.OpenArgs & "'"   ' Use this for a Text ID
 'rst.FindFirst "[ EventsID] = " & Me.OpenArgs          ' Use this for a Numeric ID
  If Not rst.NoMatch Then
      Me.Bookmark = rst.Bookmark
   Else
    DoCmd.GoToRecord , , acNewRec
    Me. EventsID = Me.OpenArgs
   End If

rst.Close
Set rst = Nothing
End If

End Sub
In the called form, for New Record Only
Code:
Private Sub Form_Load()

If Not IsNull(Me.OpenArgs) Then
   DoCmd.GoToRecord , , acNewRec
   Me. EventsID = Me.OpenArgs
 End If

End Sub


Notice these lines in the second code example:
Code:
rst.FindFirst "[ EventsID] = '" & Me.OpenArgs & "'"   ' Use this for a Text ID
 'rst.FindFirst "[ EventsID] = " & Me.OpenArgs          ' Use this for a Numeric ID
Which of these lines you'll need to use depends, as indicated, on whether your ID Field is defined as a Number or as a Text Datatype.

Linq ;0)>
 

Tay

likes garlic
Local time
Today, 22:05
Joined
May 24, 2002
Messages
269
Not my thread, but I'd just like to say thanks for this code. It's helped me out with the db I'm currently working on and I need it in another too.

Cheers!
 

missinglinq

AWF VIP
Local time
Today, 17:05
Joined
Jun 20, 2003
Messages
6,423
The more people we can help, the merrier! :D

Linq ;0)>
 

Users who are viewing this thread

Top Bottom