How is this returning a blank value?

前端 未结 1 912
轻奢々
轻奢々 2021-01-20 04:08

So this code is meant to serve as a simple search system to go to certain records in a recordset. I originally had it so they had to click the btnGoToID button in order to p

相关标签:
1条回答
  • 2021-01-20 04:37

    I think your problem is related to the fact that a text box has 2 properties, .Value and .Text, which appear similar but behave differently.

    While you have an edit in progress in the text box, the changing content is available via the .Text property. However, the content of the .Value property has not yet been updated to match.

    After the text box's After Update event, .Value will contain the new content. And if focus has moved away from the text box, its .Text property will no longer even be available.

    Sorry, I couldn't think how to explain that better. But I think the situation will be clearer with this KeyPress event procedure:

    Private Sub txtUnitNoToSearch_KeyPress(KeyAscii As Integer)
        Debug.Print "Text: '" & Me.txtUnitNoToSearch.Text & "'"
        Debug.Print "Value: '" & Me.txtUnitNoToSearch.Value & "'"
    End Sub
    

    Watch the output from Debug.Print in the Immediate window as you make changes to the context of the text box. (Ctrl+g will open the Immediate window.)

    One final point is that just Me.txtUnitNoToSearch gets you its default property which is .Value. Keep that in mind as you work through the rest of your code.

    0 讨论(0)
提交回复
热议问题