self_teachin01
02-01-2005, 12:05 PM
Hello everyone. This is my first post and I'm grateful for the help in advance. I'm learning VBA on the fly with no mentor, just one badly written book and a lot of trial and error, so the answer is probably some obvious thing I missed.
I have a sequential multi-form data entry process for a database I'm building. I've been trying to limit access to editing prior records to only upon a certain button press, and then only to a given subset of records based on entries in a prior form.
My buttons to intiate this "edit mode" where edit access is granted and to return to "view mode" where it's not granted work fine. The problem is that the form is supposed to *open* in viewonly mode, and it refuses to - opens in Edit Mode every time. The very same commands that successfully turn edit access on and off as events of On_Click
for some reason will not obey in On_Load or even On_Unload. At one point I had 3 redundant commands and yet, every time I open this form I can edit the records until I begin using the "Edit Mode" and "View Mode" buttons.
I'm posting all relevant code sections below, including the button from the prior form that opens the one I'm discussing. What I believed were my redundant commands to make sure the form opens in non-edit-mode are in bold, as are the button commands to switch to non-edit and back that do work
Note that I know that I could just manually set the form properties to default AllowEdit = No and AllowAdditions = No. But that doesn't explain why code that should work doesn't.
Code - Initial Form Button To Open Main Form
Private Sub CoverNewSkills_Click()
On Error GoTo Err_CoverNewSkills_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Basic Activity Info (S)"
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormReadOnly, , Me.CICADUNITMASTER.Value
DoCmd.Close acForm, "Cover A"
Exit_CoverNewSkills_Click:
Exit Sub
Code: Main Form (On_Load, On_Unload, On_Click of Edit Mode/View Mode Button)
Private Sub Form_Load()
Me.CICADValueStorage = Me.OpenArgs
Me.AddRecord.Visible = False
Me.Form.AllowEdits = False
Me.Form.AllowAdditions = False
Private Sub Form_Unload(Cancel As Integer)
Me.Form.RecordSource = "SELECT * FROM [Basic Activity Info (S)]"
EditMode.Caption = "Go To Edit Mode"
DoCmd.OpenForm ("Institutions (S)"), , , , acFormEdit
Me.Form.AllowEdits = False
Me.Form.AllowAdditions = False
Private Sub EditMode_Click()
If EditMode.Caption = "Go To Edit Mode" Then
If Me.OpenArgs = Me.CICADUnitBasicS Then
Me.Form.RecordSource = "SELECT * FROM WHERE _
[Basic Activity Info (S)].CICADUnitBasicS = Forms![Basic Activity Info (S)]! _
[CICADUnitBasicS]"
EditMode.Caption = "Return to View Mode"
[b]Me.Form.AllowEdits = True
Me.Form.AllowAdditions = True
Me.AddRecord.Visible = True
Else: MsgBox ("You can only edit records from the unit that " & _
"you selected in the initial setup screen.")
End If
Else
Me.Form.RecordSource = "SELECT * FROM [Basic Activity Info (S)]"
EditMode.Caption = "Go To Edit Mode"
Me.Form.AllowEdits = False
Me.Form.AllowAdditions = False
Me.AddRecord.Visible = False
End If
End Sub
So why on earth won't it work? It seems like this sort of think happens to me every day learning this language, and boy is it frustrating.
Thanks,
self_teachin01
UPDATE: (2PM)
One tiny piece of information that may or may not help:
The first time I add one of these controls in and then try to open the form through the prior form, I get an error message saying "The OpenForm Action was canceled." If I open the form directly (skipping the readonly command, maybe?), close it again, and then go in the correct way (through the prior form) there is no error message and it opens in the wrong mode like before.
I have a sequential multi-form data entry process for a database I'm building. I've been trying to limit access to editing prior records to only upon a certain button press, and then only to a given subset of records based on entries in a prior form.
My buttons to intiate this "edit mode" where edit access is granted and to return to "view mode" where it's not granted work fine. The problem is that the form is supposed to *open* in viewonly mode, and it refuses to - opens in Edit Mode every time. The very same commands that successfully turn edit access on and off as events of On_Click
for some reason will not obey in On_Load or even On_Unload. At one point I had 3 redundant commands and yet, every time I open this form I can edit the records until I begin using the "Edit Mode" and "View Mode" buttons.
I'm posting all relevant code sections below, including the button from the prior form that opens the one I'm discussing. What I believed were my redundant commands to make sure the form opens in non-edit-mode are in bold, as are the button commands to switch to non-edit and back that do work
Note that I know that I could just manually set the form properties to default AllowEdit = No and AllowAdditions = No. But that doesn't explain why code that should work doesn't.
Code - Initial Form Button To Open Main Form
Private Sub CoverNewSkills_Click()
On Error GoTo Err_CoverNewSkills_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "Basic Activity Info (S)"
DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormReadOnly, , Me.CICADUNITMASTER.Value
DoCmd.Close acForm, "Cover A"
Exit_CoverNewSkills_Click:
Exit Sub
Code: Main Form (On_Load, On_Unload, On_Click of Edit Mode/View Mode Button)
Private Sub Form_Load()
Me.CICADValueStorage = Me.OpenArgs
Me.AddRecord.Visible = False
Me.Form.AllowEdits = False
Me.Form.AllowAdditions = False
Private Sub Form_Unload(Cancel As Integer)
Me.Form.RecordSource = "SELECT * FROM [Basic Activity Info (S)]"
EditMode.Caption = "Go To Edit Mode"
DoCmd.OpenForm ("Institutions (S)"), , , , acFormEdit
Me.Form.AllowEdits = False
Me.Form.AllowAdditions = False
Private Sub EditMode_Click()
If EditMode.Caption = "Go To Edit Mode" Then
If Me.OpenArgs = Me.CICADUnitBasicS Then
Me.Form.RecordSource = "SELECT * FROM WHERE _
[Basic Activity Info (S)].CICADUnitBasicS = Forms![Basic Activity Info (S)]! _
[CICADUnitBasicS]"
EditMode.Caption = "Return to View Mode"
[b]Me.Form.AllowEdits = True
Me.Form.AllowAdditions = True
Me.AddRecord.Visible = True
Else: MsgBox ("You can only edit records from the unit that " & _
"you selected in the initial setup screen.")
End If
Else
Me.Form.RecordSource = "SELECT * FROM [Basic Activity Info (S)]"
EditMode.Caption = "Go To Edit Mode"
Me.Form.AllowEdits = False
Me.Form.AllowAdditions = False
Me.AddRecord.Visible = False
End If
End Sub
So why on earth won't it work? It seems like this sort of think happens to me every day learning this language, and boy is it frustrating.
Thanks,
self_teachin01
UPDATE: (2PM)
One tiny piece of information that may or may not help:
The first time I add one of these controls in and then try to open the form through the prior form, I get an error message saying "The OpenForm Action was canceled." If I open the form directly (skipping the readonly command, maybe?), close it again, and then go in the correct way (through the prior form) there is no error message and it opens in the wrong mode like before.