read only form allows date to change

S

sue gray

I have a form that I open in read only that has a calendar popup for the date
fields. When I open the form the calendar pop up allows the date to be
changed. The rest of the fields are read only. Any suggestions. Thanks

Private Sub ViewActivityNote_Click()
On Error GoTo Err_ViewActivityNote_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FRM - Activity Note"

stLinkCriteria = "[activitynoteid]=" & Me![activitynoteid]
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormReadOnly

Exit_ViewActivityNote_Click:
Exit Sub

Err_ViewActivityNote_Click:
MsgBox Err.Description
Resume Exit_ViewActivityNote_Click

End Sub

__________________________________
Option Compare Database
Option Explicit

Public Today As Control, ctldate As Control

Function PopCalendar()
On Error GoTo PopCalendar_Err

Set ctldate = Screen.ActiveControl
DoCmd.OpenForm "FRM - Calendar"

PopCalendar_Exit:
Exit Function

PopCalendar_Err:
MsgBox "Error:" + Error$
Resume PopCalendar_Exit

End Function
 
A

Allen Browne

Perhaps you could refuse to open the calendar (or refuse to write the date
back), if the form is read-only or the control is not visible/enabled.

Testing the Visible/Enabled properties of Screen.ActiveControl is easy
enough.

What's more challenging is determining the form that the control is on
(particularly if it is in an option group, on a tab control, in a subform,
etc.) Then you still have to test for all the factors that could make that
form read-only, e.g. AllowEdits (but AllowAdditions if at NewRecord),
RecordsetType, whether the source query is read-only (and in some cases,
some fields in a query are while others are not), user's permissions
(security), read-only status of database, etc.
 
A

Allen Browne

Sue, if you want to follow up on this, I've never had much success with
trying to work with Screen.ActiveControl.Form, so here's a routine that will
let you get a reference to the form that the active control is on.

You could use it like this:
With FormOf(Screen.ActiveControl)
Debug.Print .Name & " permits changes = ";
If .NewRecord Then
Debug.Print .AllowAdditions
Else
Debug.Print .AllowEdits
End If
End With


Public Function FormOf(varControl As Variant) As Form
On Error GoTo Err_Handler
'Purpose: Return a reference to the form the control is on.
'Argument: The control whose form you seek.
'Return: Form variable, or Nothing on error.
Dim obj As Object

If IsObject(varControl) Then
Set obj = varControl
Do While Not TypeOf obj Is Form
Set obj = obj.Parent
Loop
If TypeOf obj Is Form Then
Set FormOf = obj
End If
End If

Exit_Handler:
Set obj = Nothing
Exit Function

Err_Handler:
Select Case Err.Number
Case 91, 2450 To 2452, 2459 'Object not set, invalid form/report/view,
No parent.
'do nothing
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description,
vbExclamation, "FormOf()"
End Select
Resume Exit_Handler
End Function

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Allen Browne said:
Perhaps you could refuse to open the calendar (or refuse to write the date
back), if the form is read-only or the control is not visible/enabled.

Testing the Visible/Enabled properties of Screen.ActiveControl is easy
enough.

What's more challenging is determining the form that the control is on
(particularly if it is in an option group, on a tab control, in a subform,
etc.) Then you still have to test for all the factors that could make that
form read-only, e.g. AllowEdits (but AllowAdditions if at NewRecord),
RecordsetType, whether the source query is read-only (and in some cases,
some fields in a query are while others are not), user's permissions
(security), read-only status of database, etc.

sue gray said:
I have a form that I open in read only that has a calendar popup for the
date
fields. When I open the form the calendar pop up allows the date to be
changed. The rest of the fields are read only. Any suggestions. Thanks

Private Sub ViewActivityNote_Click()
On Error GoTo Err_ViewActivityNote_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FRM - Activity Note"

stLinkCriteria = "[activitynoteid]=" & Me![activitynoteid]
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormReadOnly

Exit_ViewActivityNote_Click:
Exit Sub

Err_ViewActivityNote_Click:
MsgBox Err.Description
Resume Exit_ViewActivityNote_Click

End Sub

__________________________________
Option Compare Database
Option Explicit

Public Today As Control, ctldate As Control

Function PopCalendar()
On Error GoTo PopCalendar_Err

Set ctldate = Screen.ActiveControl
DoCmd.OpenForm "FRM - Calendar"

PopCalendar_Exit:
Exit Function

PopCalendar_Err:
MsgBox "Error:" + Error$
Resume PopCalendar_Exit

End Function
 
S

sue gray

Wow, I didn't realize it was that complicated. If I choose your last
response, where would I put that code. THanks for the help.

Allen Browne said:
Sue, if you want to follow up on this, I've never had much success with
trying to work with Screen.ActiveControl.Form, so here's a routine that will
let you get a reference to the form that the active control is on.

You could use it like this:
With FormOf(Screen.ActiveControl)
Debug.Print .Name & " permits changes = ";
If .NewRecord Then
Debug.Print .AllowAdditions
Else
Debug.Print .AllowEdits
End If
End With


Public Function FormOf(varControl As Variant) As Form
On Error GoTo Err_Handler
'Purpose: Return a reference to the form the control is on.
'Argument: The control whose form you seek.
'Return: Form variable, or Nothing on error.
Dim obj As Object

If IsObject(varControl) Then
Set obj = varControl
Do While Not TypeOf obj Is Form
Set obj = obj.Parent
Loop
If TypeOf obj Is Form Then
Set FormOf = obj
End If
End If

Exit_Handler:
Set obj = Nothing
Exit Function

Err_Handler:
Select Case Err.Number
Case 91, 2450 To 2452, 2459 'Object not set, invalid form/report/view,
No parent.
'do nothing
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description,
vbExclamation, "FormOf()"
End Select
Resume Exit_Handler
End Function

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Allen Browne said:
Perhaps you could refuse to open the calendar (or refuse to write the date
back), if the form is read-only or the control is not visible/enabled.

Testing the Visible/Enabled properties of Screen.ActiveControl is easy
enough.

What's more challenging is determining the form that the control is on
(particularly if it is in an option group, on a tab control, in a subform,
etc.) Then you still have to test for all the factors that could make that
form read-only, e.g. AllowEdits (but AllowAdditions if at NewRecord),
RecordsetType, whether the source query is read-only (and in some cases,
some fields in a query are while others are not), user's permissions
(security), read-only status of database, etc.

sue gray said:
I have a form that I open in read only that has a calendar popup for the
date
fields. When I open the form the calendar pop up allows the date to be
changed. The rest of the fields are read only. Any suggestions. Thanks

Private Sub ViewActivityNote_Click()
On Error GoTo Err_ViewActivityNote_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FRM - Activity Note"

stLinkCriteria = "[activitynoteid]=" & Me![activitynoteid]
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormReadOnly

Exit_ViewActivityNote_Click:
Exit Sub

Err_ViewActivityNote_Click:
MsgBox Err.Description
Resume Exit_ViewActivityNote_Click

End Sub

__________________________________
Option Compare Database
Option Explicit

Public Today As Control, ctldate As Control

Function PopCalendar()
On Error GoTo PopCalendar_Err

Set ctldate = Screen.ActiveControl
DoCmd.OpenForm "FRM - Calendar"

PopCalendar_Exit:
Exit Function

PopCalendar_Err:
MsgBox "Error:" + Error$
Resume PopCalendar_Exit

End Function
 
A

Allen Browne

The FormOf() function goes in a standard module.

You would then use it in whatever way you need in the function where you
call the calendar.

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

sue gray said:
Wow, I didn't realize it was that complicated. If I choose your last
response, where would I put that code. THanks for the help.

Allen Browne said:
Sue, if you want to follow up on this, I've never had much success with
trying to work with Screen.ActiveControl.Form, so here's a routine that
will
let you get a reference to the form that the active control is on.

You could use it like this:
With FormOf(Screen.ActiveControl)
Debug.Print .Name & " permits changes = ";
If .NewRecord Then
Debug.Print .AllowAdditions
Else
Debug.Print .AllowEdits
End If
End With


Public Function FormOf(varControl As Variant) As Form
On Error GoTo Err_Handler
'Purpose: Return a reference to the form the control is on.
'Argument: The control whose form you seek.
'Return: Form variable, or Nothing on error.
Dim obj As Object

If IsObject(varControl) Then
Set obj = varControl
Do While Not TypeOf obj Is Form
Set obj = obj.Parent
Loop
If TypeOf obj Is Form Then
Set FormOf = obj
End If
End If

Exit_Handler:
Set obj = Nothing
Exit Function

Err_Handler:
Select Case Err.Number
Case 91, 2450 To 2452, 2459 'Object not set, invalid
form/report/view,
No parent.
'do nothing
Case Else
MsgBox "Error " & Err.Number & ": " & Err.Description,
vbExclamation, "FormOf()"
End Select
Resume Exit_Handler
End Function

Allen Browne said:
Perhaps you could refuse to open the calendar (or refuse to write the
date
back), if the form is read-only or the control is not visible/enabled.

Testing the Visible/Enabled properties of Screen.ActiveControl is easy
enough.

What's more challenging is determining the form that the control is on
(particularly if it is in an option group, on a tab control, in a
subform,
etc.) Then you still have to test for all the factors that could make
that
form read-only, e.g. AllowEdits (but AllowAdditions if at NewRecord),
RecordsetType, whether the source query is read-only (and in some
cases,
some fields in a query are while others are not), user's permissions
(security), read-only status of database, etc.

I have a form that I open in read only that has a calendar popup for
the
date
fields. When I open the form the calendar pop up allows the date to
be
changed. The rest of the fields are read only. Any suggestions.
Thanks

Private Sub ViewActivityNote_Click()
On Error GoTo Err_ViewActivityNote_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "FRM - Activity Note"

stLinkCriteria = "[activitynoteid]=" & Me![activitynoteid]
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormReadOnly

Exit_ViewActivityNote_Click:
Exit Sub

Err_ViewActivityNote_Click:
MsgBox Err.Description
Resume Exit_ViewActivityNote_Click

End Sub

__________________________________
Option Compare Database
Option Explicit

Public Today As Control, ctldate As Control

Function PopCalendar()
On Error GoTo PopCalendar_Err

Set ctldate = Screen.ActiveControl
DoCmd.OpenForm "FRM - Calendar"

PopCalendar_Exit:
Exit Function

PopCalendar_Err:
MsgBox "Error:" + Error$
Resume PopCalendar_Exit

End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top