Results 1 to 4 of 4
  1. #1
    SusanCoder is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2016
    Posts
    34

    Question set label attributes after opening a form as data entry

    Hi. I have a form named [OKIL Main Screen] (which I didn't name) and it's opened from two different "On Click" event procedures as 1) data entry only or 2) to view/edit data. When opened for data entry, I use this code, which works fine as far as the field values being null.



    Code:
     Private Sub DataEntry_Click()On Error GoTo Err_DataEntry_Click
    
    
        Dim stDocName As String
        Dim stLinkCriteria As String
    
    
        stDocName = "OKIL Main Screen"
        
        DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormAdd
        
    Exit_DataEntry_Click:
        Exit Sub
    
    
    Err_DataEntry_Click:
        MsgBox Err.Description
        Resume Exit_DataEntry_Click
        
    End Sub
    My problem is this: when the form opens as data entry, some label formatting has not been reset. I'd like to set the formatting as

    Code:
     Me.Label403.ForeColor = vbBlack
    Me.boxSSBenefit.Visible = False
    I'm not sure where to put the formatting reset code. The "Me" reference doesn't work in the "On Click" event proc because I'm not in the "OKIL Main Screen" form, and I don't know if I can even reset the formatting for form objects in the "On Click" event proc. When the form is loaded in view/edit mode, there's a lot of code in the "On Load" event procedure, including some if statements to set the formatting for the same labels, so I'm not sure if putting code for the data entry mode will work here. When I go to the "On Load" event proc in data entry mode, it looks like the same event proc as the view/edit mode (which may be as designed.)

    Here's an example of the "On Load" event proc if statements/formatting settings for the view/edit mode, which is working fine.

    Code:
     If Me.SSBenefit = No Then   Me.Label403.ForeColor = vbBlack
       Me.boxSSBenefit.Visible = False
    Else
       Me.Label403.ForeColor = vbWhite
       Me.boxSSBenefit.Visible = True
    End If
    I appreciate your help and consideration.

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    To have it in the click event you'd use the full reference:

    http://www.theaccessweb.com/forms/frm0031.htm
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,932
    another option is to have to code in your OKI form load event

    me.boxSSBenefit.Visible = me.dataentry


    or

    if me.dataentry then

    else

    end if

  4. #4
    SusanCoder is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Mar 2016
    Posts
    34

    Smile

    Thank you, pbaldy and Ajax. The code works beautifully. I believe either of your solutions would have worked. I chose Ajax's solution and incorporated the If statement/data entry property with the other if statements in the On Load event proc of the [Main OKIL Screen] form. I didn't know about the DataEntry property; glad to learn and use something new. The link from pbaldy is very useful and I refer to it often. Here's my final working code that turns the label formatting off when the form is opened in data entry mode, incorporated with the existing if statements that are used when the form is opened in view/edit mode...

    Code:
    If Me.DataEntry Then    
        Me.Label403.ForeColor = vbBlack
        Me.boxSSBenefit.Visible = False
    Else
        If Me.SSBenefit = No Then
            Me.Label403.ForeColor = vbBlack
            Me.boxSSBenefit.Visible = False
        Else
            Me.Label403.ForeColor = vbWhite
            Me.boxSSBenefit.Visible = True
        End If
    End If
    Thanks, again, for your quick and workable solutions. This forum is invaluable to me.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Macro to Change label before opening Form
    By Brigsy29591 in forum Macros
    Replies: 3
    Last Post: 09-01-2015, 09:08 AM
  2. Replies: 1
    Last Post: 04-25-2014, 11:41 AM
  3. Replies: 5
    Last Post: 03-09-2014, 07:16 PM
  4. Replies: 0
    Last Post: 11-07-2010, 01:28 PM
  5. Opening Form in Data Entry Mode Problem
    By alsoto in forum Forms
    Replies: 1
    Last Post: 05-28-2009, 07:45 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums