VBA pass string value to textbox

powersp68232

New Member
Joined
Apr 24, 2018
Messages
12
I have an If ElseIf in VBA and the code runs when I click a button. I have an unbound textbox [text97] that the VBA fills and a textbox [text63] that its default value = [text97]. When running the code, [text97] shows the correct value, but [text63] equals “”. If I comment out all the ElseIf statements it works as it should. I’m really stumped. Any help would be greatly appreciated. My code is as follows:

Code:
[COLOR=#000000][FONT=Arial]
If Me!txtTranBOM Like "1094.*" Then[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial]               Me!Text97 = "HCU BOM: " & Me!txtHCUBOM & " S/N: " & Me!txtHCUSN & vbCrLf & "TCU BOM: " & Me!txtTCUBOM & " S/N: " & Me!txtTCUSN & vbCrLf & "Sensor Unit BOM: " & " S/N: "[/FONT][/COLOR]

[COLOR=#000000][FONT=Arial]ElseIf Me!txtTranBOM Like "1087.*" Then[/FONT][/COLOR]
             [COLOR=#000000][FONT=Arial]Me!Text97 = "Mech BOM: " & Me!txtHCUBOM & " S/N: " & Me!txtHCUSN & vbCrLf & "E-Mod BOM: " & Me!txtTCUBOM & " S/N: " & Me!txtTCUSN[/FONT][/COLOR]

[COLOR=#000000][FONT=Arial]ElseIf Me!txtTranBOM Like "1112.*" Then[/FONT][/COLOR]
             [COLOR=#000000][FONT=Arial]Me!Text97 = "HCU BOM: " & Me!txtHCUBOM & " S/N: " & Me!txtHCUSN & vbCrLf & "TCU BOM: " & Me!txtTCUBOM & " S/N: " & Me!txtTCUSN & vbCrLf & "Sensor Unit BOM: " & " S/N: "[/FONT][/COLOR]

[COLOR=#000000][FONT=Arial]ElseIf Me!txtTranBOM Like "1102.010*" Then[/FONT][/COLOR]
[COLOR=#000000][FONT=Arial]               Me!Text97 = "Mech BOM: " & Me!txtHCUBOM & " S/N: " & Me!txtHCUSN & vbCrLf & "E-Mod BOM: " & Me!txtTCUBOM & " S/N: " & Me!txtTCUSN[/FONT][/COLOR]


[COLOR=#000000][FONT=Arial]Me!Text63 = Me!Text97[/FONT][/COLOR]

[COLOR=#000000][FONT=Arial]End If[/FONT][/COLOR]
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
What is the value of Me!txtTranBOM when this happens? What is the value of Me!Text97 before you get to the If-ElseIf construct?
 
Upvote 0
Me!txtTransBOM is 1094.020.081 and Me!Text97 is blank. Once the If-ElseIf starts Me!Text97 holds the correct value, but Me!Text63 = "".
 
Upvote 0
Ah! I think I see the problem. Trying moving the End If before the Me!Text63 = Me!Text97.

Rich (BB code):
If Me!txtTranBOM Like "1094.*" Then
               Me!Text97 = "HCU BOM: " & Me!txtHCUBOM & " S/N: " & Me!txtHCUSN & vbCrLf & "TCU BOM: " & Me!txtTCUBOM & " S/N: " & Me!txtTCUSN & vbCrLf & "Sensor Unit BOM: " & " S/N: "

ElseIf Me!txtTranBOM Like "1087.*" Then
             Me!Text97 = "Mech BOM: " & Me!txtHCUBOM & " S/N: " & Me!txtHCUSN & vbCrLf & "E-Mod BOM: " & Me!txtTCUBOM & " S/N: " & Me!txtTCUSN

ElseIf Me!txtTranBOM Like "1112.*" Then
             Me!Text97 = "HCU BOM: " & Me!txtHCUBOM & " S/N: " & Me!txtHCUSN & vbCrLf & "TCU BOM: " & Me!txtTCUBOM & " S/N: " & Me!txtTCUSN & vbCrLf & "Sensor Unit BOM: " & " S/N: "

ElseIf Me!txtTranBOM Like "1102.010*" Then
               Me!Text97 = "Mech BOM: " & Me!txtHCUBOM & " S/N: " & Me!txtHCUSN & vbCrLf & "E-Mod BOM: " & Me!txtTCUBOM & " S/N: " & Me!txtTCUSN

End If

Me!Text63 = Me!Text97
 
Last edited:
Upvote 0
Solution
iliace that was exactly the issue!! Thanks so much for the help. Had me beating my brain trying to figure out what was wrong.
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,191
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top