10 replies
by sl-campbell
I am not sure how you are calling the sub forms, but if you have a command button with a DoCmd.OpenForm, then you can assign opening arguments for the form, (ie. DoCmd.OpenForm "frmDEPT", acNormal, , , acReadOnly, , cDATAVIEW
cDATAVIEW is one oftwo public constants that I made for this demo. These constants are in a module:
'===========================
'Module1
Option Compare Database
Option Explicit
Public Const cDATAVIEW% = 0
Public Const cDATAENTRY% = 1
'===========================
You can define these as you wish and add more constants.
So. now go to the sub form to be opened by the DoCmd. In design view of the form, go to the menu point 'View' and click on 'Code'. The code window will open. There are 2 drop downs at the top of the code window. Click on the left one and select 'Form'. An Event (Load) should be placed in the code window for by default if there are no other events for the form object. We do not need this event for this demo. We need the Open event. You will need to select it from the right drop down. The Open event automatically fires when the form opens. In this event place the following code:
'===========================
Private Sub Form_Open(Cancel As Integer)
Dim vOpenOptions As Variant
vOpenOptions = Me.OpenArgs
'If no opening arguments were passed the set to the default
If IsNull(vOpenOptions) Then vOpenOptions = cDATAVIEW
Select Case vOpenOptions
Case cDATAENTRYMe.DataEntry = True
'Here, more properties can be set
Case Else 'cDATAVIEW = default
Me.DataEntry = False
'Here, more properties can be set
End Select
End Sub
'===========================
by sl-campbell
Ran out of space!
Continued.............
'===========================
Then in order to call the sub form you can use a 2 command buttons with the following code:
Private Sub cmdOpenFormAddNew_Click()
On Error GoTo Err_OpenForm
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmDEPT"
'Change the OpenArgs parameter to cDATAVIEW for the command button that opens the form to view all data.
'You can add arguments to open the form as read only, or whatever, either in the DoCmd or by passing the arguments via OpenArgs.
DoCmd.OpenForm stDocName, acNormal, , stLinkCriteria, , OpenArgs:=cDATAENTRY
Exit_OpenForm:
Exit Sub
Err_OpenForm:
MsgBox Err.Description
Resume Exit_OpenForm
End Sub
Ok, this is only for demonstration purposes and was created 'on the run', but I think you will get the idea. You can set the properties for the form or its' objects.
Have fun!
by sl-campbell
by wkmtn
by wkmtn
by sl-campbell
by wkmtn
by sl-campbell
by wkmtn
by wkmtn
This discussion is closed to new replies.
Trending Web Development posts
Sort by Trending