Here is what I'm trying to accomplish. I have one form with a button on it that calls another form to add additional information. I want to be able verify that there is not already data entered for the specific record. The reason it is a separate form and not a subform is that the data in the 2nd form can be independent of the data on the first (although there is a 1-to-1 relationship between the underlying tables, each can have records the other does not).
To make this more clear...I have a form to enter different events. Another form is used to track materials distributed. However, sometimes materials are distributed at events. I want to be able to link the materials to the events if materials are sent to the events, but be able to enter materials separately if materials are sent to people. In addition, not all events have materials distributed. When clicking on a button to call the materials form, I want it to first check to make sure that there is not already a materials record for the event. If a record does already exist, I want to be able to view it in case additions or corrections are needed. The tables are linked by an ID (with that ID being passed from the event form to the materials form via OpenArgs when the materials record is created).
With that being said, I created code that copies certain data from the events form and parses it to the materials form using OpenArgs. The OpenArgs part works (with thanks going to RuralGuy for his help). However, I can't seem to get the find part to work to check whether materials already exist for an event. Below is my code. What the code does is the part after the find which places values in textboxes. It seems to skip over any searching. If it does search, then it skips the displaying part and goes directly to creating a new record with the parsed data from the OpenArgs. I want this to be one or the other, not both. Either it displays the matching record or creates a new record with the parsed data.
Thanks in advance.
-------------------------------------------------------------------------------------------------------
Private Sub Form_Load()
Dim Args As Variant
If Not IsNull(Me.OpenArgs) Then
Args = Split(Me.OpenArgs, ";")
If Not IsNull(Args(6)) Then
Dim strID As String
strID = Args(6)
Dim RS As DAO.Recordset
Set RS = Me.RecordsetClone
RS.FindFirst "EventID = '" & _
strID & "'"
If Not RS.NoMatch Then
Me.Bookmark = RS.Bookmark
Exit Sub
End If
End If
Me.EventName = Args(0)
Me.EventDate = Args(1)
Me.Zip = Args(2)
'Me.ZipPlusFour = Args(3)
Me.City = Args(4)
Me.State = Args(5)
Me.EventID = Args(6)
End If
End Sub
To make this more clear...I have a form to enter different events. Another form is used to track materials distributed. However, sometimes materials are distributed at events. I want to be able to link the materials to the events if materials are sent to the events, but be able to enter materials separately if materials are sent to people. In addition, not all events have materials distributed. When clicking on a button to call the materials form, I want it to first check to make sure that there is not already a materials record for the event. If a record does already exist, I want to be able to view it in case additions or corrections are needed. The tables are linked by an ID (with that ID being passed from the event form to the materials form via OpenArgs when the materials record is created).
With that being said, I created code that copies certain data from the events form and parses it to the materials form using OpenArgs. The OpenArgs part works (with thanks going to RuralGuy for his help). However, I can't seem to get the find part to work to check whether materials already exist for an event. Below is my code. What the code does is the part after the find which places values in textboxes. It seems to skip over any searching. If it does search, then it skips the displaying part and goes directly to creating a new record with the parsed data from the OpenArgs. I want this to be one or the other, not both. Either it displays the matching record or creates a new record with the parsed data.
Thanks in advance.
-------------------------------------------------------------------------------------------------------
Private Sub Form_Load()
Dim Args As Variant
If Not IsNull(Me.OpenArgs) Then
Args = Split(Me.OpenArgs, ";")
If Not IsNull(Args(6)) Then
Dim strID As String
strID = Args(6)
Dim RS As DAO.Recordset
Set RS = Me.RecordsetClone
RS.FindFirst "EventID = '" & _
strID & "'"
If Not RS.NoMatch Then
Me.Bookmark = RS.Bookmark
Exit Sub
End If
End If
Me.EventName = Args(0)
Me.EventDate = Args(1)
Me.Zip = Args(2)
'Me.ZipPlusFour = Args(3)
Me.City = Args(4)
Me.State = Args(5)
Me.EventID = Args(6)
End If
End Sub