Results 1 to 9 of 9
  1. #1
    DDS is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Apr 2018
    Posts
    24

    Forcing unbound text box to save it's value

    I have a popup form which allows a user to enter a new customer.
    I have designed this form so that the user is entering values in various unbound text boxes first.
    VBA code in the 'Save' command button's Click event transfers the values into corresponding bound fields.
    I have found this method skirts of a lot of issues involved with entering the data straight into bound fields.


    I thought the above info was contextually necessary for my query:

    I am trying to add a search capability on the double-click event of the first unbound text box 'CustomerEntry' (where the customer's name is entered)
    I had a command button for this function positioned next to the text box (working successfully) but I'm trying to de-clutter the form.
    The idea for the search is that the user can easily access details like phone number and address etc to enter into the succeeding fields.

    My issue is that unless I click out of the unbound 'CustomerEntry' text box and then click back into it my code has not recognised the value that has just been entered into this field.
    So when data is first entered it still behaves as if the value is null. If the value has been changed (text deleted and new text typed) the search is carried out on the previous text that was 'saved'.
    Remembering that the current record has not yet been 'dirtied' (nor do I want it to be in case the user decides to cancel).

    Is there a way to 'save' the value of this unbound text box so my code recognises the value that was just entered without having to click out of the field first? Remembering I want to keep the current record as a new record.

    I have tried setting focus to a different text box then back into it using VBA but this doesn't seem to have the same effect as doing this with mouse clicks.

    My code:
    Code:
    Private Sub CustomerEntry_DblClick(Cancel As Integer)
    
    
        Dim strSearchBase As String
        Dim strSearchItem As String
       
        strSearchBase = "https://www.google.com.au/search?q="
        strSearchItem = Me.CustomerEntry & ""
       
        Me.TypeEntry.SetFocus 
        Me.CustomerEntry.SetFocus  ' my unsuccessful attempt at forcing the value of Me.CustomerEntry to be saved
    
    
        If Len(strSearchItem) > 0 Then
            Application.FollowHyperlink strSearchBase & strSearchItem
        Else
            DoCmd.Beep
            MsgBox "Enter the customer name you wish to search for.", , "No Customer Entered"
        End If
        
    End Sub

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,535
    Can you post a copy of the db for us to play with
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    DDS is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Apr 2018
    Posts
    24
    It's over 15 MB and I think that is stopping me from uploading it.
    Would you like me to strip a copy of it down to the relevant form and table and upload that?

  4. #4
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows 7 32bit Access 2013
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,535
    Just need something with a few dummy records to illustrate your problem
    Make it a zip file will help

  5. #5
    DDS is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Apr 2018
    Posts
    24
    Ok stripped down database is attached Bob, (was still too large zipped).

    Alt + H while Menu is active should display the ribbon etc if you need it, (and just 'H' to hide it all again).

    I've just left a button to the culprit form on the main menu.

    When you open it, type a value into the 'Customer' field and then without taking the focus away from that field try double clicking it.
    However if you type a value into it then click off it then double click it, the search carries out as expected.
    Same applies if you have text already in it but change the text, the search is carried out on the previous text unless you click off the field first.
    Attached Files Attached Files

  6. #6
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,404
    There's an invisible "Google Customer" button on the form. Why not make that visible and then copy the code from the double click event on the search box to the on_click event for the command button?
    That's much more intuitive for the user anyway.

    Read your Original post again, saw that you are trying to de-clutter.
    So do this with new strSearchArg:
    Code:
    Private Sub CustomerEntry_DblClick(Cancel As Integer)
    
    
        Dim strSearchBase As String
        Dim strSearchItem As String
        Dim strSearchArg As String
        strSearchBase = "https://www.google.com.au/search?q="
        strSearchItem = Me.CustomerEntry & ""
       
        Me.TypeEntry.SetFocus
        Me.CustomerEntry.SetFocus
        strSearchArg = CustomerEntry.Value
        If Len(strSearchArg) > 0 Then
            Application.FollowHyperlink strSearchBase & strSearchArg
        Else
            DoCmd.Beep
            MsgBox "Enter the customer name you wish to search for.", , "No Customer Entered"
        End If
        
    End Sub
    BTW, suggest adding OPTION EXPLICIT at top of all code modules.
    Last edited by davegri; 06-17-2018 at 12:37 PM. Reason: sp

  7. #7
    DDS is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Apr 2018
    Posts
    24
    Thanks I'll give that a try tomorrow.

  8. #8
    DDS is offline Novice
    Windows 7 64bit Access 2016
    Join Date
    Apr 2018
    Posts
    24
    Thanks Dave,
    Your suggested code made me realise what the problem was.
    I needed to assign the strSearchItem value after taking the focus away and back again.

    This code now works as expected:
    Code:
    Private Sub CustomerEntry_DblClick(Cancel As Integer)
    
    
        Dim strSearchBase As String
        Dim strSearchItem As String
       
        strSearchBase = "https://www.google.com.au/search?q="
        
        Me.TypeEntry.SetFocus
        Me.CustomerEntry.SetFocus
        strSearchItem = Me.CustomerEntry & ""
        If Len(strSearchItem) > 0 Then
            Application.FollowHyperlink strSearchBase & strSearchItem
        Else
            DoCmd.Beep
            MsgBox "Enter the customer name you wish to search for.", , "No Customer Entered"
        End If
        
    End Sub

  9. #9
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,404
    Good job. Glad it's working for you. Good luck with the rest of your project.

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

Similar Threads

  1. Save last entry in unbound text boxes
    By gunitinug in forum Access
    Replies: 2
    Last Post: 08-29-2017, 07:16 AM
  2. Replies: 3
    Last Post: 10-08-2012, 08:40 AM
  3. Unbound Form, but wish to save records...how?
    By LostInAccess in forum Forms
    Replies: 4
    Last Post: 07-18-2012, 09:55 AM
  4. Forcing text to upper case
    By barrettp in forum Forms
    Replies: 10
    Last Post: 06-01-2010, 09:44 AM
  5. Replies: 3
    Last Post: 10-15-2009, 12:24 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