473,326 Members | 2,805 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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

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.

2 1783
NeoPa
32,556 Expert Mod 16PB
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
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

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

Similar topics

4
by: Dave | last post by:
Hi, I tried something with 'return value' of a function and i got two different behaviours. My question is: why does method 1 not work? Thanks Dave method 1: here, whatever i choose (ok or...
6
by: George | last post by:
Hi All, I thought this would not compile because no return value is specified. But it does compile and run (aix and xlc v7.0.) Could someone kindly please point me to where in the spec this...
4
by: bluedolphin | last post by:
This is my first function in Visual and I'm having a simple syntax syntax issue that I'm hoping someone can help correct for me. I have a function Public Function...
8
by: Ravindranath Gummadidala | last post by:
Hi All: I am trying to understand the C function call mechanism. Please bear with me as I state what I know: "every invocation of a function causes a frame for that function to be pushed on...
3
by: Neelesh Bodas | last post by:
Hello all, Just wanted a small clarification on these two points : 1) The following code compiles well - int f() try { throw "xyz"; } catch(...) {
20
by: lovecreatesbeauty | last post by:
Hello experts, Is the following code snippet legal? If it is, how can exit() do the keyword return a favor and give a return value to the main function? Can a function call (or only this...
4
by: arnuld | last post by:
1.) we usually say /return 0/ indicates success e.g #include <iostream> int main() { int i=3; std::cout << i << std::endl; return 0;
4
by: liyanage | last post by:
I recently worked on error handling and three related issues/questions came up. 1.) I am trying to trigger Apache ErrorDocument handlers by setting appropriate HTTP status codes in my PHP...
1
by: Calder Coalson | last post by:
I was searching for ways to get the return value from os.system() calls, when I came across this from 6 years ago. I tried what was suggested in this thread, but output =...
68
by: Jim Langston | last post by:
I remember there was a thread a while back that was talking about using the return value of a function as a reference where I had thought the reference would become invalidated because it was a...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.