Results 1 to 9 of 9
  1. #1
    LeonS is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jul 2014
    Posts
    115

    Tabbing Stopped By Coding ???


    Hello! I have written into my coding a facility that changes the BackColor (to light blue) when the field is GotFocus. The field BackColor returns to white on LostFocus. It works perfectly on about 10 fields in succession (Title, Initials, GivenName, FamilyName etc etc). However in one field (Company) on GetFocus, no problem but the cursor will not leave that field by using the tab or return. The AdComany form is a dialogue box that allows the user to enter a company name. If the name is in the Compaanies table already, the name is shown. If the company does not exist in the Companies table, the user enters a new company name. To leave that form there is a "Done" button, which closes the AddCompany form. What am I doing wrong? The code is as follows:

    Code:
    Private Sub Company_GotFocus()Dim ctl As Control
    
    
        DoCmd.OpenForm "AddCompany", acNormal, "", "", acEdit, acNormal
        DoCmd.RunCommand acCmdRefresh
        
        Set ctl = Me.ActiveControl
        If ctl.BackColor = 16777215 Then
            ctl.BackColor = 15913666
        Else
            ctl.BackColor = 16777215
        End If
        
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,944
    Why open AddCompany form just because control gets focus? I tried this and I not only can't get out of that field, I can't get the second form to stay closed. End up in a loop. Closing second form and returning to first form means Company field gets focus again and opens second form again - this would go on forever.

    If not already, suggest using a combobox to select company and its NotInList event to manage opening AddCompany form to add a new company 'on the fly' during data entry - open form if it is needed. Get that code out of the GotFocus event.
    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
    LeonS is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jul 2014
    Posts
    115
    June7 - thanks for that. It is the existing system and is similar to the results to a ComboBox. I will investigate.
    In the meantime, is that the reason the tabbing does not work? It used to work before I added the colour change code. Leon

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,944
    I edited my previous answer. I don't see how it could have worked. Does not for me. And I tested without the color code.
    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.

  5. #5
    LeonS is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jul 2014
    Posts
    115
    June7 - but it does work for me!!??? This is the code under the "Done" button in the AddCompany form which accepts the input and closes the form. The cursor then moves on to the next field (Website).

    Code:
    Private Sub Done_Click()On Error GoTo Err_Done_Click
    
    
        Forms![Contacts]![Company] = Me.Company.Value
        Forms![Contacts]![IDCompany] = Me.IDCompany.Value
        Forms![Contacts]![WebSite] = Me.WebSite.Value
    
    
        If Me.Dirty Then Me.Dirty = False
        DoCmd.Close
    
    
    Exit_Done_Click:
        Exit Sub
    
    
    Err_Done_Click:
        MsgBox Err.Description
        Resume Exit_Done_Click
        
    End Sub

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,944
    Instead of me trying to replicate - if you want to provide db for analysis, follow instructions at bottom of my post.
    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.

  7. #7
    LeonS is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jul 2014
    Posts
    115
    June7 - thanks for your help. As you suggested, I am trying to go the "NotInList" route and I am using the following code. The ComboBox is based on a table called "Companies". In that table, apart from the primary IDCompany, there is a field called "Company" and one called "WebSite". The value is saved in the Master1 table, which has a field "IDCompany". I have tried to run the code/ box and the first part works - it shows the message box asking if I want to add, on saying 'Yes', an error comes up saying it does not recognise the field name Company. Would you please do me a favour and check the code for me? Thanks, Leon

    Code:
    Private Sub Combo266_NotInList(NewData As String, Response As Integer)
    
        Dim strSQL As String
        Dim i As Integer
        Dim Msg As String
    
    
        'Exit this sub if the combo box is cleared
        If NewData = "" Then Exit Sub
    
    
        Msg = "'" & NewData & "' is not currently in the list." & vbCr & vbCr
        Msg = Msg & "Do you want to add it?"
    
    
        i = MsgBox(Msg, vbQuestion + vbYesNo, "Unknown Company...")
        If i = vbYes Then
            strSQL = "Insert Into Companies ([strCompany]) " & _
                     "values ('" & NewData & "');"
            CurrentDb.Execute strSQL, dbFailOnError
            Response = acDataErrAdded
        Else
            Response = acDataErrContinue
        End If
        
    End Sub

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,944
    You have strCompany as field name, not Company.

    But if you would rather open a form so other info about company can be entered, review https://blueclawdatabase.com/notinlist-event-code/
    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.

  9. #9
    LeonS is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jul 2014
    Posts
    115
    June7 - Brilliant!! Sorry I was so stupid! All is working well! All I need to do is get the code to do a "Proper Case" on LostFocus. I have some code, which works on all the other fields, but not on this one!! Thanks, again. Leon

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

Similar Threads

  1. Split Form Tabbing
    By pmangan in forum Access
    Replies: 2
    Last Post: 10-12-2017, 03:47 PM
  2. Tabbing through tab controls
    By cowboy in forum Forms
    Replies: 1
    Last Post: 04-30-2012, 12:32 PM
  3. Odd tabbing through Rows
    By Glenwood in forum Access
    Replies: 1
    Last Post: 09-05-2011, 05:39 PM
  4. Tabbing nightmare
    By Remster in forum Forms
    Replies: 3
    Last Post: 11-24-2010, 11:35 AM
  5. Tabbing order
    By emccalment in forum Forms
    Replies: 1
    Last Post: 02-18-2010, 10:58 AM

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