Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    twgonder is offline Expert
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    714

    Event for after form displays, before entry in tbox control?

    Here's another little stumper I've gotten myself into.
    I searched, but no go.

    I'm working on a logon form.
    There isn't a data source.
    The first field to enter is the "User ID"

    I need to test a lot of conditions to see if the system is available before the User ID is entered,


    and if not available, I want to show that in the caption of the form (where I show most errors).

    But... I can't find an even that allows me to run a procedure after the form displays, but before the first textbox has any entry.
    All the stops I've tried (there have been many) happen without the form being displayed.
    Even enter and got focus for the textbox.

    Where?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    I tested GotFocus for textbox. Form is visible when event runs.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    twgonder is offline Expert
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    714
    @June7 Very strange, it doesn't for me on Access 2021. I'll try again, maybe because I was in the debugger watching the code?

    P.S. I did try without using the debugger, and I was able to change the caption, it just didn't update, or display the form, while stepping through the code.
    Other similar changes while the form has displayed normally work and show an immediate change in the open object pane.
    It probably has something to do with User ID being the first control.

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Why not just do it before you show the form?
    Then if conditions are not met, you show a form that explains what is wrong, else show the logon form.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    How are you opening your logon form? Autoexec or startup form from the backstage?
    I would run whatever it is your doing from a sub called from an autoexec and have the sub open your form.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  6. #6
    twgonder is offline Expert
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    714

    How show errors?

    @ Welshgasman This brings up a good question I've been waiting to ask, and I hate asking it here, as I'll be accused of topic creep, but since you asked...

    When you find entry errors in a form during entry or at before update (and you don't want to use the Access cryptic messages), is it common practice to pop-up another form, use a message box or a customized programmed message box to display, or have a textbox or label hidden that appears with the errors in the current form? Since I'm implementing foreign language conversion for label names and error messages, I'm avoiding "hard coding" the text and have a function to return the translation value.
    Last edited by twgonder; 10-18-2022 at 05:50 PM. Reason: to whom since it wasn't added

  7. #7
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    is it common practice to pop-up another form, yes - as a custom message box

    use a message box or a customized programmed message box to display, yes

    or have a textbox or label hidden that appears with the errors in the current form? I say No.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    I would say whatever works for the situation - if there is only potential for one error, use a message box, if multiple errors you could use a custom popup to display all the messages. As a user I would find it very irritating to get a message box 'error A', I fix that then get another message 'error B', etc

    Another method is to highlight in some way (conditional formatting perhaps) each control where there is an error then use a message box to tell the user that the highlighted controls need fixing.

    Depends on what the potential errors could be, but if a required value, I often use the format property to display a message whilst the control is null e.g. to display 'Required' for a text value the format property would be @;[Red]"Required" - then the before update message won't appear, unless the user ignores the prompt

  9. #9
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,423
    if multiple errors you could use a custom popup
    Agree with the multi-prompt thing, but you don't need a form for this (not saying you shouldn't). Have done multi-line message box detailing the missing values a few times. In such a form, I would always leave the labels attached/associated with the controls to be validated. That way, you can easily get the label caption since the label caption is usually less cryptic than txtCustPrimePhone. Changing bg colour at the same time is an option as well.
    Last edited by Micron; 10-18-2022 at 07:20 PM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  10. #10
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    I do the label thing like micron as its usually descriptive and can be hidden if necessary.

    Code:
    Public Function ValidateForm(frm As Form, TagCharacter As String) As Boolean
    'validated controls must have a label. Ok to use a hidden label if needed.
    
    
        Dim ctl As Control
        Dim flg As Boolean
        Dim strout As String
    
    
        flg = True
    
    
        For Each ctl In frm.Controls
    
    
            If ctl.Tag = TagCharacter Then
                If Nz(ctl.value, "") = "" Then
                    flg = False
                    ctl.BorderColor = vbRed
                    strout = strout & Space(10) & "* " & ctl.Controls.Item(0).Caption & vbNewLine
                Else
                    ctl.BorderColor = vbBlack
                End If
    
    
            End If
        Next
    
    
        If flg = False Then
            MsgBox "The following field(s) must be completed:" & vbNewLine & strout
        End If
    
    
        ValidateForm = flg
    
    
    End Function
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  11. #11
    twgonder is offline Expert
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    714
    Quote Originally Posted by moke123 View Post
    I do the label thing like micron as its usually descriptive and can be hidden if necessary.

    ...
    This is a great idea for when loading the form, put all required fields in a red border text box. I don't use the tag property. Is there a simple way to see if data is required for a control? (I'm still foggy on how Access relates field types, length, required and format from a table into the text/combo boxes of forms).

  12. #12
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    I don't use the tag property. Is there a simple way to see if data is required for a control?
    yes, use the tag property and loop through the controls.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  13. #13
    twgonder is offline Expert
    Windows 10 Access 2016
    Join Date
    Jun 2022
    Location
    Colombia
    Posts
    714
    Quote Originally Posted by moke123 View Post
    yes, use the tag property and loop through the controls.
    I'm not sure what you mean by using the tag property.

  14. #14
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    6,556
    Quote Originally Posted by twgonder View Post
    I'm not sure what you mean by using the tag property.
    Each control has a property called Tag ?

    Look on the Other tab of any control, bottom field.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  15. #15
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,879
    I'm not sure what you mean by using the tag property.
    I believe we've discussed the tag property before.

    Click image for larger version. 

Name:	tagprop.PNG 
Views:	16 
Size:	8.5 KB 
ID:	48924
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 06-04-2018, 06:46 AM
  2. Replies: 4
    Last Post: 10-18-2014, 10:53 PM
  3. Replies: 6
    Last Post: 11-18-2013, 04:50 PM
  4. Form entry Control
    By Raury in forum Forms
    Replies: 1
    Last Post: 08-03-2011, 08:41 AM
  5. Replies: 4
    Last Post: 12-01-2010, 02:42 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