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