Maybe posting the code behind that control may help us get a picture.
Also, I'm not clear if you already have had code on the (sub) form's
open/load/current event to set the property accordingly.
WRT the error, I believe that this is because Data Entry is one of
properties that can be only set in design view or something similar to
that. Makes sense, really, as the forms behaves very differently in a
data entry mode compared to the usual mode and switching between would
raise lot of hackles, I imagine. You probably could get away with it by
doing something like:
<pseudocode>
Application.Echo False
Me.MySubform.SourceObject = ""
DoCmd.OpenForm "MySubform", acDesign, acHidden
Forms("MySubform").DataEntry = XXX
DoCmd.Save '<== Risky as it may save other objects and you may not want
that! See if you can get a specific object name instead; check VBA help
DoCmd.Close acForm "MySubform"
Me.MySubform.SourceObject = "MySubform"
Application.Echo True
<pseudocode>
Note: You also should check the VBA file on 'Data Entry property'; it
may have something to say about changing the property at runtime.
Thanks for the help again and the quick response.
Form procedure:
user gets prompt from frm01ReportEdit. This form has 2 criteria that
must be filed.
(this opens the main form (frm01ReportEdit)
***********CODE START frm01ReportEdit*********
Private Sub cmdFindAdd_Click()
'requires a reference set for Microsoft DAO 3.x Object Library
On Error GoTo HandleError
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Dim strForm As String
Dim strDialog As String
Dim strLine As String
Dim strShift As String
Dim intAnswer As Integer
Dim Response As Integer
'all three criteria required
'If any criteria is missing, say so and exit Sub
If Nz(Me.cmbDate, "") = "" Or Nz(Me.cmbShift, "") = "" Then
MsgBox "Missing Date, Shift, or Area! Please enter all
criteria before clicking find.", vbOKOnly, "Oops!"
Exit Sub
Else
Set db = CurrentDb()
'create SQL
strSQL = "SELECT pkReport FROM tbl100Report"
strSQL = strSQL & " WHERE [dtmDate] = #" & [Forms]!
[frm01ReportEdit]![cmbDate] & "# "
strSQL = strSQL & " AND [strShift] = '" & [Forms]!
[frm01ReportEdit]![cmbShift] & "' ;"
' open recordset
Set rs = db.OpenRecordset(strSQL)
'check for records
If rs.BOF And rs.EOF Then
'Send msgbox to ask wether to enter data or if entry was a
mistake
intAnswer = MsgBox("There is no current entry for " &
vbCrLf & Chr(34) & Me.cmbDate & _
" " & Me.cmbShift & _
" Shift " & _
" " & Chr(34) & "." & vbCrLf & _
"Would you like to add it to now?"
_
, vbQuestion + vbYesNo, "No Report
Found?")
Select Case intAnswer
Case vbYes
'set cursor to hourglass
DoCmd.Hourglass (True)
'open form in add mode
DoCmd.OpenForm "frm01Report",
acNormal, , , acFormAdd, acWindowNormal
'set lookups for criteria to input to form
Forms!frm01Report.dtmDate.Value =
Me.cmbDate
Forms!frm01Report.cmbShift.Value =
Me.cmbShift
DoCmd.Hourglass (False)
strDialog = "frm01ReportEdit"
DoCmd.Close acForm, strDialog, acSaveNo
Exit Sub
Case vbNo
'Tell user to try again, resume
MsgBox "Please try again." _
, vbInformation, "Data Entry"
Exit Sub
End Select
Else
'set cursor to hourglass
DoCmd.Hourglass (True)
rs.MoveLast
rs.MoveFirst
'***************Filter CODE******************
DoCmd.OpenForm "frm01Report", acNormal, , "[pkReport] = "
& rs!pkReport
DoCmd.Hourglass (False)
End If
End If
HandleError_Exit:
On Error Resume Next
Exit_cmdFindAdd_Click:
'clean up
rs.Close
Set rs = Nothing
Set db = Nothing
strDialog = "frm01ReportEdit"
DoCmd.Close acForm, strDialog, acSaveNo
Exit Sub
HandleError:
MsgBox Err.Number & " - " & Err.Description
Resume HandleError_Exit
End Sub
***********CODE END frm01ReportEdit*********
Description of frm01Report:
frm01Report has three subforms frm02Machine, frm06MaintenanceAdd
(dataentry), frm06MaintenanceEdit
frm02Machine has 6 subforms in it: to keep from typing all that
look in the code
On the frm01Report there is a button cmdApproval
This button set True and False to a ysn field which is disabled.
When the button is clicked, prompt for password, if match, set ysn to
true, disable subforms except frm02Machine which needs to be left
alone because the user can still look at it, but not change the data.
I don't know if locking the fields would be any different.
anyway, here's the code for the cmdApproval button:
***********CODE START frm01ReportEdit cmdApproval*********
Private Sub cmdApprove_Click()
On Error GoTo Err_cmdApprove_Click
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Dim strUser As String
Dim strInput As String
Dim strMsg As String
Set db = CurrentDb()
strUser = Environ("username") 'NT LoginID
'set SQL to query USER password from Windows USER name
strSQL = "SELECT Password FROM tblADMINpassword WHERE Login = '" &
strUser _
& "' AND ysnActive = -1 AND password <> null AND
ysnApprove = -1;"
'set recordset from the SQL
Set rs = db.OpenRecordset(strSQL)
If rs.BOF And rs.EOF Then
Beep
'if no psw exisits
MsgBox "You have no password or" & vbCr & "not allowed to
approve reports", vbCritical, "Error"
'exit the routine
Exit Sub
Else
If Me.ysnLocked = 0 Then
strMsg = "Do you want to lock and approve the Report?" &
vbCrLf & vbLf & "Please enter your Password."
strInput = InputBoxDK(Prompt:=strMsg, Title:="Lock and
Approve Report")
If strInput = rs!Password Then
Me.frm02Machine.Form!txtPress.SetFocus
Me.strApproved = strUser
Me.dtmApprovedOn = Now()
Me.ysnLocked = -1
Me.frm02Machine.Form!fkPress.Enabled = False
Me.frm02Machine.Form!cmdAdd.Enabled = False
Me.frm02Machine.Form!intLunch.Enabled = False
Me.frm02Machine.Form!intBreaks.Enabled = False
Me.frm02Machine.Form!intPlannedDT.Enabled = False
Me.frm02Machine.Form!frm03ProductionAdd.Enabled =
False
Me.frm02Machine.Form!frm03ProductionEdit.Enabled =
False
Me.frm02Machine.Form!frm04Downtime.Enabled = False
Me.frm02Machine.Form!frm04DowntimeEdit.Enabled = False
Me.frm02Machine.Form![Scrap Entry].Enabled = False
Me.frm02Machine.Form![Scrap Edit].Enabled = False
Me.MachineAdded.Enabled = False
Me.cmdApprove.Caption = "UnApprove Report"
Beep
MsgBox "The Report has been Approved." & vbCrLf & vbLf
& "The report is now Locked.", _
vbInformation, "Report Condition"
ElseIf strInput = "" Then
Exit Sub
Else
Beep
MsgBox "Incorrect Password!" & vbCrLf & vbLf & "Report
Not Approved or Locked." _
& vbCrLf & vbLf & "Failed attemp has been
logged!", vbCritical, "Invalid Password"
Exit Sub
End If
Else
strMsg = "Do you want to unapprove the Report?" & vbCrLf &
vbLf & "Please enter your Password to edit."
strInput = InputBoxDK(Prompt:=strMsg, Title:="UnLock and
UnApprove Report")
If strInput = rs!Password Then
Me.strApproved = ""
Me.dtmApprovedOn = ""
Me.ysnLocked = 0
Me.frm02Machine.Form!fkPress.Enabled = True
Me.frm02Machine.Form!cmdAdd.Enabled = True
Me.frm02Machine.Form!intLunch.Enabled = True
Me.frm02Machine.Form!intBreaks.Enabled = True
Me.frm02Machine.Form!intPlannedDT.Enabled = True
Me.frm02Machine.Form!frm03ProductionAdd.Enabled =
True
Me.frm02Machine.Form!frm03ProductionEdit.Enabled =
True
Me.frm02Machine.Form!frm04Downtime.Enabled = True
Me.frm02Machine.Form!frm04DowntimeEdit.Enabled =
True
Me.frm02Machine.Form![Scrap Entry].Enabled = True
Me.frm02Machine.Form![Scrap Edit].Enabled = True
Me.MachineAdded.Enabled = True
Me.cmdApprove.Caption = "Approve Report"
MsgBox "Correct Password!" & vbCrLf & vbLf &
"Report unlocked for Editing." _
& vbCrLf & vbLf & "Approval has been
Removed.", vbInformation, "Unlock Successful"
Exit Sub
ElseIf strInput = "" Then
Exit Sub
Else
Beep
MsgBox "Incorrect Password!" & vbCrLf & vbLf & "Report
Not Unapproved or unLocked." _
& vbCrLf & vbLf & "Failed attemp has been
logged!", vbCritical, "Invalid Password"
Exit Sub
End If
End If
End If
Exit_cmdApprove_Click:
rs.Close
Set rs = Nothing
Set db = Nothing
Exit Sub
Err_cmdApprove_Click:
MsgBox "Runtime Error # " & Err.Number & vbCrLf & vbLf &
Err.Description
Resume Exit_cmdApprove_Click
End Sub
***********CODE END frm01ReportEdit cmdApproval*********