×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Open a new blank sub form record connected to main form

Open a new blank sub form record connected to main form

Open a new blank sub form record connected to main form

(OP)

Hi

I'm trying to open a new blank record for data entry linked to whatever person/record i'm on.

For example, i if i want to add new bookings to record 1 (lngPeopleID). I should just be able to click on the new booking command button, the form should open with the correct lngPeopleID with blank fields to fill in.

Main form: frmCustomers (tblCustomers), lngPeopleID (PrimaryKey)
Subform (frmCustomersBookingSubform), qryBookings, lngBookingID (Primary Key), lngPeopleID (ForeignKey)

The subform on the main form is just for viewing only, it can't be edited and the user can only click on edit booking command button on the main form which brings up a pop up form which they can then edit, close it down which refreshes the subform again.

I know how to jump to a record to edit a booking via the subform with this:

CODE

Private Sub EditBooking_cmdbutton_Click()

    Dim stDocName As String
    Dim stLinkCriteria As String
    stDocName = "frmAddEditBookings"
    If Me.Dirty Then Me.Dirty = False
    DoCmd.OpenForm stDocName, , , stLinkCriteria, , , Me![frmCustomersBookings Subform].Form![lngBookingID]
    
Exit_EditBooking_cmdbutton_lest_Click:
    Exit Sub

Err_EditBooking_cmdbutton_lest_Click:
    MsgBox Err.Description
    Resume Exit_EditBooking_cmdbutton_lest_Click

End Sub 

I just want to be able to add a new booking to a new persons record, i did try:

CODE

Private Sub AddNewBooking_cmdbutton_Click()
On Error GoTo Err_AddNewBooking_cmdbutton_Click

    Dim stDocName As String
    Dim stLinkCriteria As String

    stDocName = "frmAddNewBooking"
    DoCmd.OpenForm stDocName, , , stLinkCriteria, , , Me.lngPeopleID
    DoCmd.GoToRecord , , acNewRec

Exit_AddNewBooking_cmdbutton_Click:
    Exit Sub

Err_AddNewBooking_cmdbutton_Click:
    MsgBox Err.Description
    Resume Exit_AddNewBooking_cmdbutton_Click
    
    

End Sub 

All this does is open a blank record but it isn't linked to the person, i do have the OpenArgs in the OnLoad event of the form

CODE

Private Sub Form_Load()
If Len(Me.OpenArgs) > 0 Then
        Dim rs As Object
        Set rs = Me.Recordset.Clone
        rs.FindFirst "[lngPeopleID]=" & Me.OpenArgs
        Me.Bookmark = rs.Bookmark
    End If
End Sub 

Just can't figure it out

Michael

RE: Open a new blank sub form record connected to main form

I believe you need to set the Default Value in the add form.

CODE --> vba

Private Sub Form_Load()
    If Len(Me.OpenArgs) > 0 Then
        Me.[lngPeopleID].DefaultValue = Me.OpenArgs
    End If
End Sub 


Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016

RE: Open a new blank sub form record connected to main form

(OP)

I really appreciate your help Duane.

Thanks so much

RE: Open a new blank sub form record connected to main form

SpartansFC,
You don't have any code that will "brings up a pop up form which they can then edit, close it down which refreshes the subform again." Is this working as expected?

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016

RE: Open a new blank sub form record connected to main form

(OP)
Hi Duane

It does work, on the OnClose event i have

CODE

Forms!frmCustomers![frmCustomersBookings Subform].Form.Requery 

This seems to do the trick

RE: Open a new blank sub form record connected to main form

Thanks for the clarification. Sometimes developers will place the Requery code in the main form after the add form has been opened. This would only work if the add form was opened acDialog. Your method should work well.

Duane
Minnesota
Hook'D on Access
MS Access MVP 2001-2016

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close