I feel so dirty!

brewpedals

Registered User.
Local time
Today, 09:34
Joined
Oct 16, 2002
Messages
32
Can you please take a look at this code and tell me what I'm doing wrong?

Objects on the form are not enabled on new records even if my criteria matches??

This code is on the click event of a "New Record" button that launches lauches a form, creates a new record and puts the userID into the OwnerID field.

Code:
Private Sub cmd_AddNew_Click()
On Error GoTo Err_cmd_AddNew_Click

    Dim stDocName As String

    stDocName = "frm_DMSS"
    DoCmd.OpenForm stDocName
    Forms!frm_DMSS.DataEntry = True
    Forms!frm_DMSS.AllowAdditions = True
    Forms!frm_DMSS.AllowEdits = True
    Forms!frm_DMSS.Form.Caption = "Create a NEW Document record."
    DoCmd.GoToRecord acDataForm, stDocName, acNewRec
    [B]Forms!frm_DMSS!txt_OwnerID.Value = Forms!frm_DetectIdleTime!UserID.Value[/B]
    Forms!frm_DMSS!Date = Date
    Forms!frm_DMSS!txt_Plant.Value = DLookup("[Plant_ID]", "tbl_Users", "[ID] =" & Forms!frm_DetectIdleTime!UserID.Value)
    
Exit_cmd_AddNew_Click:
    Exit Sub

Err_cmd_AddNew_Click:
    MsgBox Err.Description
    Resume Exit_cmd_AddNew_Click
    
End Sub

This is the form open event code that first checks to see if it's a new record then saves the record to record the userID as the ownerID in the record the sets permissions to objects.

Code:
Private Sub Form_Open(Cancel As Integer)
    
    Dim strUserID As Single
    Dim strOwnerID As Single
    
    If Me.Dirty Then
        Me.Dirty = False
    Else
        GoTo SetPermissions
    End If

SetPermissions:
    
    strUserID = Forms!frm_DetectIdleTime!UserID.Value
    strOwnerID = Me!txt_OwnerID.Value
   
   Select Case strOwnerID
        Case Is = strUserID
            Me.[Form].[AllowAdditions] = True
            Me.[Form].[AllowEdits] = True
            Me.[Form].[AllowDeletions] = True
        Case Is <> strUserID
            Me.[Form].[AllowAdditions] = False
            Me.[Form].[AllowEdits] = False
            Me.[Form].[AllowDeletions] = False
            Me.Rev_date.OnClick = ""
            Me.cmd_Delete_doc.Enabled = False
            Me.cmd_delete_file.Enabled = False
            Me.cmd_send.Enabled = False
            Me.cmd_browse.Enabled = False
            Me.Frame372.Enabled = False
            Me.Child399.Enabled = False
            Me.ctl_subfrm_DMSS_Access.Enabled = False
            Me.ctl_subfrm_DMSS_Controls.Enabled = False
            Me.ctl_subfrm_DMSS_Revision.Enabled = False
            Me.ctl_subfrm_DMSS_Roles.Enabled = False
End Sub

Thanks so much for your time - it's a lot of code to weed through!
Brew.
 
brewpedals said:
Code:
Private Sub cmd_AddNew_Click()
On Error GoTo Err_cmd_AddNew_Click

    Dim stDocName As String

    stDocName = "frm_DMSS"
    DoCmd.OpenForm stDocName
    Forms!frm_DMSS.DataEntry = True
    Forms!frm_DMSS.AllowAdditions = True
    Forms!frm_DMSS.AllowEdits = True
    Forms!frm_DMSS.Form.Caption = "Create a NEW Document record."
    DoCmd.GoToRecord acDataForm, stDocName, acNewRec
    [B]Forms!frm_DMSS!txt_OwnerID.text = Forms!frm_DetectIdleTime!UserID.text[/B]
    Forms!frm_DMSS!Date = Date
    Forms!frm_DMSS!txt_Plant.Value = DLookup("[Plant_ID]", "tbl_Users", "[ID] =" & Forms!frm_DetectIdleTime!UserID.Value)
    
Exit_cmd_AddNew_Click:
    Exit Sub

Err_cmd_AddNew_Click:
    MsgBox Err.Description

'---- pointless you are gonna end the sub anyway
'    Resume Exit_cmd_AddNew_Click
    
End Sub

Try Text instead of value - I've put it in above...

This is the form open event code that first checks to see if it's a new record then saves the record to record the userID as the ownerID in the record the sets permissions to objects.

Code:
Private Sub Form_Open(Cancel As Integer)
    
    Dim strUserID As Single
    Dim strOwnerID As Single
    
    If Me.Dirty Then Me.Dirty = False

'---- next two lines are pointless since you are always going to call it
'    Else
'        GoTo SetPermissions
'    End If

SetPermissions:
    
    strUserID = Forms!frm_DetectIdleTime!UserID.Value
    strOwnerID = Me!txt_OwnerID.Value
   

'---- the next bit I'm not sure - break point and debug to see
'---- I've changed the italic bits
   Select Case strOwnerID
[i]        Case strUserID[/i]
            Me.AllowAdditions = True
            Me.AllowEdits = True
            Me.AllowDeletions = True
        Case Else
            Me.AllowAdditions = False
            Me.AllowEdits = False
            Me.AllowDeletions = False

'---- onclick ="" ?????????? What?
'            Me.Rev_date.OnClick = ""

'---- you don't need ME. for everything - VB/VBA thinks that 
'---- Me on a form module means the form and uses it anyway.
'---- You only need Me to specify the form object for reference purposes
            cmd_Delete_doc.Enabled = False
            cmd_delete_file.Enabled = False
            cmd_send.Enabled = False
            cmd_browse.Enabled = False
            Frame372.Enabled = False
            Child399.Enabled = False
            ctl_subfrm_DMSS_Access.Enabled = False
            ctl_subfrm_DMSS_Controls.Enabled = False
            ctl_subfrm_DMSS_Revision.Enabled = False
            ctl_subfrm_DMSS_Roles.Enabled = False
[b]    end select[/b]
End Sub

Thanks so much for your time - it's a lot of code to weed through!
Brew.

Post up your results

Vince
 

Users who are viewing this thread

Back
Top Bottom