473,322 Members | 1,480 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,322 software developers and data experts.

Problem with If/Then/Else code

22
I have a form with a tabbed control on it. I am trying to set certain criteria for some of the tabs to show only when info from other fields meet criteria.

Specifically, I have two fields. Both are combo boxes (using tables as the row source).

What I want is that when empType combo box is set to Prehire (8 in the table) AND the empPosition combo box is set to Police Officer then the Police_MSK tab is visible. But if both of those conditions aren't met then I don't want that tab showing.

What might complicate this is that for all other Prehires (non Police Officer's) I have a different tab that I want to be visible called Prehire_MSK.

Here is what my code looks like:

Expand|Select|Wrap|Line Numbers
  1. Private Sub empType_AfterUpdate()
  2.  
  3.  If Me.empType = "8" Then
  4.         Me.Prehire_MSK.Visible = True
  5.     Else
  6.         Me.Prehire_MSK.Visible = False
  7.     End If
  8.  
  9.  If Me.empType = "8" And Me.empPosition = "Police Officer" Then
  10.         Me.Police_MSK.Visible = True
  11.     Else
  12.         Me.Police_MSK.Visible = False
  13.     End If
  14.  
  15. End Sub
So after updating the empType field to Prehire I get the Prehire_MSK tab to show up and when I change that field to any other type the Prehire_MSK tab goes away like it's supposed to.

But it doesn't seem to be looking at the empPosition field and I can't get the Police_MSK tab to show up when it is a Prehire Police Officer. Can someone help me and tell me what's wrong with my code?

Am I better off using a Select Case instead of the If/Then/Else?

I hope I explained well enough what my problem is...

Thanks!
Nov 9 '09 #1

✓ answered by MMcCarthy

I think your problem is in your logic. Try this instead ....

Expand|Select|Wrap|Line Numbers
  1. Private Sub empType_AfterUpdate()
  2.  
  3.     If Me.empType = "8" And Me.empPosition = "Police Officer" Then
  4.         Me.Police_MSK.Visible = True
  5.         Me.Prehire_MSK.Visible = False
  6.     ElseIf Me.empType = "8" Then
  7.         Me.Police_MSK.Visible = False
  8.         Me.Prehire_MSK.Visible = True
  9.     Else
  10.         Me.Police_MSK.Visible = False
  11.         Me.Prehire_MSK.Visible = False
  12.     End If
  13.  
  14. End Sub

2 2084
MMcCarthy
14,534 Expert Mod 8TB
I think your problem is in your logic. Try this instead ....

Expand|Select|Wrap|Line Numbers
  1. Private Sub empType_AfterUpdate()
  2.  
  3.     If Me.empType = "8" And Me.empPosition = "Police Officer" Then
  4.         Me.Police_MSK.Visible = True
  5.         Me.Prehire_MSK.Visible = False
  6.     ElseIf Me.empType = "8" Then
  7.         Me.Police_MSK.Visible = False
  8.         Me.Prehire_MSK.Visible = True
  9.     Else
  10.         Me.Police_MSK.Visible = False
  11.         Me.Prehire_MSK.Visible = False
  12.     End If
  13.  
  14. End Sub
Nov 9 '09 #2
rleepac
22
Thank you that is much "cleaner" logic.

I figured out my problem...I was using Police Officer where I should have been using the ID number from the table that is was using as a row source.

Problem solved!

Thanks again...
Nov 9 '09 #3

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

Similar topics

0
by: Mike Hofer | last post by:
Hi everyone. I could really use some help. First, the backstory: ===================== I *really* need a 3-state checkbox for my ASP.NET application. Specifically, I need one that lets me set...
2
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c...
11
by: felixnielsen | last post by:
What i have is not even a real problem, but i hope someone can help anyway, but first a piece of code_ @code start const unsigned short Size = 2; // 2^N std::bitset<Size*Size*Size> YZ;...
18
by: len.hartley | last post by:
Hi, I am trying to pop-up a window when the user clicks on an image. The problem is that when the user clicks on the image and the window pops up OK, but the window underneath also proceeds to...
8
by: sara | last post by:
I have a report that runs fine with data. If there is no data, I have its NO Data event sending a MsgBox and cancelling the report. Then it seems I still get the 2501 message on the Open Report...
2
by: darrel | last post by:
Hi there vb masters i have a problem regrading the saving procedure in my program: Here my code: Private Sub cmdSave_Click() Dim rsShowRec As New ADODB.Recordset Dim cnn As New...
10
by: amitabh.mehra | last post by:
Hi I havent used MQT before. Read the online tips and tutorials but none seems to give any hint for my problem. I have a base table (base_table) as: st varchar(25) default...
9
by: sunita jadhav | last post by:
my question is if i type in html textbox on key press event suppose i type 12345 values in textbox then i delete or edit any value of text box suppose i edit 3 and i insert the value 6 at 3 but i...
1
kiemxai
by: kiemxai | last post by:
you see that,i did correct or not? PROBLEM ANALYSIS For an introduction to program transaction journal, see the background section of assignment . Not only transaction journal, but also inventory...
23
by: ryna | last post by:
Desperately need help.... here's the snippet of my code that im trying to solve since last week... icePayment.aspx If (Left(Request.Form("return_url"), 7) <> "http://") Then errorInput =...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.