oepn form with related records AND allow new record to be created

mary

Registered User.
Local time
Today, 09:06
Joined
Nov 14, 2000
Messages
37
Hi all!

I can create a button that opens a new form with the related records from the first form, but I would also like to be able to add a new related record.

I can add a record, but it is not picking up the ID.

frmProjectIDProject
has button that opens up second form where the IDProject is the same

I'd like to be able to add another record with the same IDproject or if there are no related records, create one.

Thanks for your help.
Mary
 
Hi Mary,

Can you include some sample code? What is the code you're using to open the second form?

You're saying that you can add a new record, but it's not picking up the ID... I don't have a good idea of what this form looks like, but I'm thinking you could have a text box bound to the project ID field (e.g., txtID) and then include the ID in the OpenArgs and set the default value of the text box based on the OpenArgs
Code:
Me.txtID.DefaultValue = Me.OpenArgs
 
Here's the code to open the form:

Private Sub Command73_Click()
Dim stDocName As String
Dim stlinkCriteria As String
stDocName = "frmUpdate3"
stlinkCriteria = "[IDProj]=" & Me![IDProj]


DoCmd.OpenForm stDocName, acNormal, , stlinkCriteria

The form that opens is a continuous form, with the correct records showing. If I add a record, I'd like it to automatically add the correct IDProj.

Thanks again,
Mary
 
Try changing the code to
Code:
DoCmd.OpenForm stDocName, acNormal, , stLinkCriteria, , , Me![IDProj]
Then you need to make sure that you have a textbox in frmUpdate3 that's bound to the IDProj field. I'm going to assume that you name it txtIDProj.

Then put this in frmUpdate3's load event
Code:
Private Sub Form_Load()
    If IsNumeric(Me.OpenArgs) Then
        Me.txtIDProj.DefaultValue = Me.OpenArgs
    End If
End Sub
That's assuming that ProjID is a number. Otherwise use something like
Code:
If Len(Me.OpenArgs) > 0 Then

You can then hide the ProjID field if you want.
 
Thanks so much! I'll give that a try!

Mary
 
Grzzlo,

Thank you!! it did the trick!!

Mary
 

Users who are viewing this thread

Back
Top Bottom