EdFred
knows enough, dangerous
- Local time
- Today, 01:34
- Joined
- Mar 2, 2007
- Messages
- 129
I have a form with 2 Combo and 1 text box. It sometimes requires repetitive mostly-but-not-quite-duplicate entries so I wrote some vba code so I don't have to manually key in the same info over and over (sometimes up to 10 times, but often it's 1 and done)
When I manually key in certain information, to the first two ComboBoxes it writes a prefix to the LotNumber text box and moves the caret to after the prefix. This it does. Never had an issue.
Non-pertinent code <np code> removed from the code snippets below
This code above works as it should - writes the prefix to LotNumber and the caret is waiting at the end of the text entry
This code above works as it should - writes the prefix to LotNumber and the caret is waiting at the end of the text entry
This code is what is causing much cursing and searching with no solution. Everything works right up until the End Sub. I put a 2 second delay/timer and a MsgBox with before the End Sub to test. While the timer is ticking and before the message box triggers the caret is blinking at the end the box after the prefix like it is supposed to. As soon as the End Sub is triggered it selects what is written in the text box and moves the carat to position 0. So as soon as I start manually entering information it overwrites the prefix.
I've moved the Public Sub to the on Enter for the LotNumber text box. No Joy.
I've done Exit Sub right after calling writePrefix. No Joy.
I've done more iterations of moving code around, but have zero solution.
I've moved to another focus, done delays, moved it back, and I always get the same result - highlighted text that get overwritten when I manually enter.
Anyone ever run into this and if so, have a solution?
When I manually key in certain information, to the first two ComboBoxes it writes a prefix to the LotNumber text box and moves the caret to after the prefix. This it does. Never had an issue.
Non-pertinent code <np code> removed from the code snippets below
Code:
Public Sub writePrefix()
If Condition 1 Then
<np code removed >
With Me.LotNumber
.Value = strPrefix
.SetFocus
Me.LotNumber.SelStart = len(strPrefix)
End With
End If
End Sub
Code:
Private Sub Invoice_Number_AfterUpdate()
<np code removed>
If condition 1 Then
<np code removed Autofills Product_ID >
writePrefix
End If
End Sub
Code:
Private Sub Product_ID_Exit(Cancel As Integer)
<np code removed - re-enters information from previous record if empty>
writePrefix
End Sub
Code:
Private Sub Invoice_Number_Exit(Cancel As Integer)
If condition 1 Then
<np code removed checks if previous record is empty>
If condition 2 Then
<np code removed writes previous record if not empty>
If condition 3 Then
<np code removed Autofills Product_ID>
writePrefix
End If
End If
End If
End Sub
This code is what is causing much cursing and searching with no solution. Everything works right up until the End Sub. I put a 2 second delay/timer and a MsgBox with before the End Sub to test. While the timer is ticking and before the message box triggers the caret is blinking at the end the box after the prefix like it is supposed to. As soon as the End Sub is triggered it selects what is written in the text box and moves the carat to position 0. So as soon as I start manually entering information it overwrites the prefix.
I've moved the Public Sub to the on Enter for the LotNumber text box. No Joy.
I've done Exit Sub right after calling writePrefix. No Joy.
I've done more iterations of moving code around, but have zero solution.
I've moved to another focus, done delays, moved it back, and I always get the same result - highlighted text that get overwritten when I manually enter.
Anyone ever run into this and if so, have a solution?