By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,647 Members | 1,444 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,647 IT Pros & Developers. It's quick & easy.

If... ElseIf does not return the value that is expected.

P: 2
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 it’s 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:

Expand|Select|Wrap|Line Numbers
  1. If Me!txtTranBOM Like "1094.*" Then
  2.  
  3.     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: "
  4.  
  5. ElseIf Me!txtTranBOM Like "1087.*" Then
  6.  
  7.    Me!Text97 = "Mech BOM: " & Me!txtHCUBOM & " S/N: " & Me!txtHCUSN & vbCrLf & "E-Mod BOM: " & Me!txtTCUBOM & " S/N: " & Me!txtTCUSN
  8.  
  9.  
  10.  
  11. ElseIf Me!txtTranBOM Like "1112.*" Then
  12.  
  13.     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: "
  14.  
  15.  
  16.  
  17. ElseIf Me!txtTranBOM Like "1102.010*" Then
  18.  
  19.     Me!Text97 = "Mech BOM: " & Me!txtHCUBOM & " S/N: " & Me!txtHCUSN & vbCrLf & "E-Mod BOM: " & Me!txtTCUBOM & " S/N: " & Me!txtTCUSN
  20.  
  21.  
  22.  
  23.     Me!Text63 = Text97
  24.  
  25. End If
Apr 24 '18 #1

✓ answered by NeoPa

When you say [Text63]="" (Empty String) are you saying that from knowledge or could it be Null (Unset) instead?

Your code seems to set the value of [Text63], which would indicate that it's unlikely you're actually using a default (.DefaultValue) at all.

You've done a fairly good job of writing your question - especially for a first one. Can we request you just clarify exactly what's happening when? Under which circumstances is the value of [Text63] not being set as expected? Which part of the code is expected to run?

NB. Only the last ElseIf seems to set [Text63]. The others only set [Text97].

PS. Using meaningful names for your controls will help you ask questions that are more meaningful. It will also help you to work in your project without making simple mistakes. There's really very little reason to continue working with default Control names. You're just working against your own interest, to save such a small amount of effort.

Share this Question
Share on Google+
2 Replies


NeoPa
Expert Mod 15k+
P: 31,261
When you say [Text63]="" (Empty String) are you saying that from knowledge or could it be Null (Unset) instead?

Your code seems to set the value of [Text63], which would indicate that it's unlikely you're actually using a default (.DefaultValue) at all.

You've done a fairly good job of writing your question - especially for a first one. Can we request you just clarify exactly what's happening when? Under which circumstances is the value of [Text63] not being set as expected? Which part of the code is expected to run?

NB. Only the last ElseIf seems to set [Text63]. The others only set [Text97].

PS. Using meaningful names for your controls will help you ask questions that are more meaningful. It will also help you to work in your project without making simple mistakes. There's really very little reason to continue working with default Control names. You're just working against your own interest, to save such a small amount of effort.
Apr 24 '18 #2

P: 2
Thanks for your help. I ended up having to move row 23 outside of the End if. This corrected my issue.
Apr 28 '18 #3

Post your reply

Sign in to post your reply or Sign up for a free account.