Question : Opening subform in dataentry mode

Experts,

Short version, I'm trying to open a form with a subform in DataEntry mode if there isn't any data available. If their is data, then the form currently opens up correctly. However, if their isn't any data, the form is completely blank with no buttons or text boxes available.

Long version

I'm opening the Main form (frmMenu_DayClean_Main) using the following code:

DoCmd.OpenForm "frmMenu_DayClean_Main", acNormal, , "[MenuDayNo_Clean] = " & Me.txtDaySelect & " AND [MenuCycleNo_Clean] = " & Me.txtCycleSelect & " AND [MenuSeasonNo_Clean] = " & Me.txtSeasonSelect & " AND [MenuOrganizationNo_Clean] = " & Me.txtOrganizationSelect

When the form open the code snippet below runs in the OnOpen event for the Main form.

I'm trying to open the subform in DataEntry mode.  I think have a sequence problem, but the code do won't run in the subform if their isn't any data.

Thanks, James
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
Private Sub Form_Open(Cancel As Integer)
    Dim sSQL As String
    sSQL = "SELECT tblMenuDayClean.MenuDayCleanID FROM tblMenuDayClean WHERE (((tblMenuDayClean.MenuDayNo_Clean)=[Forms]![frmMenu_MAIN]![txtDaySelect]) AND ((tblMenuDayClean.MenuCycleNo_Clean)=[Forms]![frmMAIN_STARTUP]![cboCycleNo]) AND ((tblMenuDayClean.MenuSeasonNo_Clean)=[Forms]![frmMAIN_STARTUP]![cboSeason]) AND ((tblMenuDayClean.MenuOrganizationNo_Clean)=[Forms]![frmMAIN_STARTUP]![cboOrganization]));"
 
    If IsNull([MenuDayCleanID]) = True Then
        
       Me.frmMenu_DayClean_Sub.Form.DataEntry = True
         MsgBox "no data"
    Else
         Me.frmMenu_DayClean_Sub.Form.DataEntry = False
         MsgBox "data"
    End If
End Sub

Answer : Opening subform in dataentry mode

you can also add the main form's record id

private sub btn_click()

me.subformName.form.allowadditions=true  'might not be needed
me.subformName.form.dataentry=true

me.subformName.form.[ID]=me.[ID]

end sub
Random Solutions  
 
programming4us programming4us