Populate form fields on open

PeregrinTook

Registered User.
Local time
Today, 22:25
Joined
Aug 1, 2006
Messages
15
Hi all,

I'm sure this must be a well used function by many access users but I can't find anything about it online at all - please help!

I want to open a subform "AddReservation" and populate three fields with data taken from the relevant record in the main form. So in the btnOpenAddReservation_Click event to open the subform I set global variables, then in the form_open event I have this:

Code:
Private Sub Form_Open(Cancel As Integer)

    Me.CatID = stLinkCatID
    Me.CatName = stLinkCatName
    Me.OwnerID = stLinkOwnerID

End Sub

But I get the error 2448 'Can't assign a value to this object'.

However if I put the same three lines into the start of the subform's btnARSave_Click event it works fine:

Code:
Private Sub btnARSave_Click()
On Error GoTo Err_btnARSave_Click

    Dim stDocName As String
    Dim stDocName2 As String
    stDocName = "OwnersAndCats"
    stDocName2 = "AddReservation"

    Me.CatID = stLinkCatID
    Me.CatName = stLinkCatName
    Me.OwnerID = stLinkOwnerID
    
    DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    
    YesNo = MsgBox("This reservation has been added successfully, do you want to add another?", vbYesNo + vbQuestion, "Add More Reservations?")
    Select Case YesNo
        Case vbYes
            DoCmd.GoToRecord , , acNext
        Case vbNo
            DoCmd.Close acForm, stDocName2
            DoCmd.Close acForm, stDocName
            DoCmd.OpenForm stDocName
            DoCmd.GoToRecord , , acGoTo, stRecordNo
      End Select

Exit_btnARSave_Click:
    Exit Sub

Err_btnARSave_Click:
    MsgBox Err.Description
    Resume Exit_btnARSave_Click
    
End Sub

What am I doing wrong? Why can't I populate the fields on open?

Many thanks
PT
 
Last edited:
Sorry, I keep referring to the form I want to open & populate as a subform but it's not at all - it's a POPUP form...

Any suggestions please?

Thanks
PT
 

Users who are viewing this thread

Back
Top Bottom