473,597 Members | 2,157 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

If function problem

6 New Member
Hello everyone, I got some problems with one of my codes. I am making a database where a person can tick boxes and chose 60credits from existing 120. But somehow my if function does not calculate the total..and at the end I get Message "Please chose 30credits per semester"

I would appreciate some help! Thank you :)

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. Option Compare Database
  4.  
  5. Private Sub ModuleOptions_Click()
  6.  
  7. Dim International_Business_1 As Integer
  8. Dim Business_Programming_1 As Integer
  9. Dim Decision_Making As Integer
  10. Dim Change_Management As Integer
  11. Dim Business_Planning As Integer
  12. Dim Small_Business_Issues As Integer
  13. Dim Decision_Analysis As Integer
  14. Dim International_Business_2 As Integer
  15. Dim Business_Programming_2 As Integer
  16. Dim Business_Finance As Integer
  17. Dim Corporate_Strategy As Integer
  18. Dim Career_Management As Integer
  19. Dim Business_Ethics As Integer
  20. Dim Corporate_Finance As Integer
  21. Dim Semester1 As Integer
  22. Dim Semester2 As Integer
  23.  
  24. Semester1 = 0
  25. Semester2 = 0
  26.  
  27. If International_Business_1 = 0 And International_Business_2 = 20 Then
  28.     MsgBox "You cannot select International Business 2 in semester 2 unless International Business 1 in semester 1 is selected.", vbCritical, "Incorrect choice"
  29.     Exit Sub
  30. End If
  31.  
  32. If Business_Programming_1 = 0 And Business_Programming_2 = 20 Then
  33.     MsgBox "You cannot select Business Programming 2 in semester 2 unless Business Programming 1 in semester 1 is selected.", vbCritical, "Incorrect choice"
  34.     Exit Sub
  35. End If
  36.  
  37. If Decision_Making = 20 And Decision_Analysis = 10 Then
  38.     MsgBox "You cannot select both Decision Making and Decision Analysis because of the common material shared", vbCritical, "Incorrect choice"
  39.     Exit Sub
  40. End If
  41.  
  42. If Business_Finance = 20 And Corporate_Finance = 10 Then
  43.     MsgBox "You cannot select both Business Finance and Corporate Finance because of the common material shared", vbCritical, "Incorrect choice"
  44.     Exit Sub
  45. End If
  46.  
  47. If Business_Planning = 10 And Corporate_Strategy = 10 Then
  48.     MsgBox "You cannot select both Business Planning and Corporate Strategy because of the common material shared", vbCritical, "Incorrect choice"
  49.     Exit Sub
  50. End If
  51.  
  52. If Management_Dissertation = 20 Then
  53.  
  54.     Semester1 = Semester1 + 10
  55.     Semester2 = Semester2 + 10
  56. End If
  57.  
  58. InternationalBusiness1.Value = International_Business_1
  59. BusinessProgramming1.Value = Business_Programming_1
  60. DecisionMaking.Value = Decision_Making
  61. ChangeManagement.Value = Change_Management
  62. BusinessPlanning.Value = Business_Planning
  63. SmallBusinessIssues.Value = Small_Business_Issues
  64. DecisionAnalysis.Value = Decision_Analysis
  65. InternationalBusiness2.Value = International_Business_2
  66. BusinessProgramming2.Value = Business_Programming_2
  67. BusinessFinance.Value = Business_Finance
  68. CorporateStrategy.Value = Corporate_Strategy
  69. CareerManagement.Value = Career_Management
  70. BusinessEthics.Value = Business_Ethics
  71. CorporateFinance.Value = Corporate_Finance
  72.  
  73. Semester1 = (Semester1 + International_Business_1 + Business_Programming_1 + Decision_Making + Change_Management + Business_Planning + Small_Business_Issues + Decision_Analysis)
  74. Semester2 = (Semester2 + International_Business_2 + Business_Programming_2 + Business_Finance + Corporate_Strategy + Career_Management + Business_Ethics + Corporate_Strategy)
  75.  
  76. If Semester1 <> 30 Or Semester2 <> 30 Then
  77.     MsgBox "Each semester should consist of 30 credits.", vbOKOnly + vbCritical, "Incorrect choice"
  78.     Exit Sub
  79. Else
  80.     MsgBox "Thank you for your time. Confirmation letter has been sent to your email adress.", vbOKOnly + vbExclamation, "Choice confirmation"
  81. End If
  82.  
  83. DoCmd.RunCommand acCmdSaveRecord
  84. DoCmd.OpenReport "Module Options", acViewPreview, , "[StudentID] = '" & [StudentID] & "'"
  85.  
  86. End Sub
  87.  
  88.  
Dec 22 '11 #1
14 1545
Mihail
759 Contributor
Jar !
From my practice I can say that more conditions after IF = more troubles.
Of course, the full skilled coders can handle that very well. But only they.
My advice is to use parenthesis in order to say to VBA exactly what you wish. As example:

Instead:
Expand|Select|Wrap|Line Numbers
  1. If International_Business_1 = 0 And International_Business_2 = 20 Then


use this:
Expand|Select|Wrap|Line Numbers
  1. If (International_Business_1 = 0) And (International_Business_2 = 20) Then


Good luck !
Dec 22 '11 #2
Jaroslavu
6 New Member
Dear Mihail,

Thank for your time, but your solution does not solve my problem. I tried to use brackets in my if statements and it still does not calculate the variables..

Jaroslav ;(
Dec 22 '11 #3
NeoPa
32,566 Recognized Expert Moderator MVP
Well, let's start with the basics and send you to base-camp (When Posting (VBA or SQL) Code) first. When we have a proper question we can think about looking at it for you.
Dec 22 '11 #4
Jaroslavu
6 New Member
Dear NeoPa,

Sorry for misunderstandin g, I am beginner at VBA for Access. The code that I have written is the one that goes on button. There is a Form where a user can tick the boxes and select modules he do want to study. After a selection of boxes user presses button and the IF function that I have written above should state whether 60credits in total (30 1semester and 30 2semester) were selected. I tried different approached to code this, but somehow I think that, there might be a mistake in line 73 and 74..but I am not sure about that.

Will appreciate any sort of help.

Thank You
Dec 22 '11 #5
NeoPa
32,566 Recognized Expert Moderator MVP
I did just try to help - but you've ignored it.

Go back to the linked page and at least follow the instructions found there. Being a beginner in Access is no reason for failing to follow simple instructions on what you must do when asking a question.
Dec 22 '11 #6
Jaroslavu
6 New Member
NeoPa,

Sorry probably you did get me wrong. The problem is that I did debug and it does not show any errors at all. Everything seems to work fine, but at the end - when i chose the options..no matter what options I chose 10 or 120credits it shows the same message that is on the line 77

Expand|Select|Wrap|Line Numbers
  1.  
  2. "Each semester should consist of 30 credits."
  3.  
  4.  
Dec 22 '11 #7
Rabbit
12,516 Recognized Expert Moderator MVP
You've created a bunch of integer variables that you never initialize. Therefore, their value is going to be 0. You then try to compare those variables to constants. Which isn't going to get you anywhere because they're never going to match since they're always 0. And then you attempt to set some, what I assume to be, controls with the values of those variables, which is always 0. And finally, you add those variables together. Which is always 0. So it doesn't matter what you check, it's always 0.
Dec 22 '11 #8
Jaroslavu
6 New Member
Hmm, maybe you have suggestions how I could solve this problem?
Dec 22 '11 #9
NeoPa
32,566 Recognized Expert Moderator MVP
Jaroslavu:
The problem is that I did debug and it does not show any errors at all.
I assume you're referring to a compile. I'm glad you at least managed to follow that instruction, though it would have been almost pointless without the Option Explicit unfortunately.
Jaroslavu:
Sorry probably you did get me wrong.
Your code doesn't have Option Explicit set. Compiling without that is more than 50% useless. This is the third post on the same issue. In what way did I remotely get you wrong?

I suspect Rabbit has outlined your main problems for you anyway, but I refuse to work on code that doesn't even have the basics done properly first. It's not like it's complicated or anything.
Dec 22 '11 #10

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

Similar topics

4
3952
by: rcb845 | last post by:
Hi everybody of the PHP community, I am using the php function "getimagesize()" to access the width/height of an image from the Web. This function should return false if image is not available. Most of the time the function works correctly, but in 2 or 3 cases I have a problem like, search is going on for minutes, and the function does
11
3745
by: Kostatus | last post by:
I have a virtual function in a base class, which is then overwritten by a function of the same name in a publically derived class. When I call the function using a pointer to the derived class (ClassB* b; b->func(); ) the base-class function is called instead of the new function in the derived class. All other similar functions (virtual in the base class and overwritten in the the derived class) work fine, it's just this one function. ...
1
1950
by: Dwayne Epps | last post by:
This is probably a no brainer, but I am having no luck at getting this to work. I'm creating functions that will validate form data fields. For example, the following function: function checkText(field, msg, min, max) { if (!min) { min = 1 } if (!max) { max = 65535 } if (!field.value || field.value.length < min || field.value.max > max || !field.value.match(/^*$/)) { alert(msg);
3
3396
by: Tomaz Rotovnik | last post by:
Hi I created very simple dll (vc++) which has three functions (start, stop and initialization). it starts capturing sound from soundblaster and when the buffer is filled with the data, dll calls VB calback function (passed with initialization) and passes the buffer size (integer type). First I have some problems with __stdcall declaration in VC dll, but I think I solved that problem. Callback function runs in separated thread under main...
5
7682
by: Ian Davies | last post by:
Dear Access expert I am trying to use an mde application developed in Access2k with Access 2002. I get an Access error box: Function is not available.. Date() etc. Is Access 2002 back compatible if so how do I work around this date function problem? Ian
8
2081
by: Mantorok Redgormor | last post by:
I have ran into a problem where I have a struct that has a member which contains a pointer to function and is initialized to a function in the initializer list. With my array of structs of this type, I have some elements of this array, thats function pointer member does not need to be initialized to a function. I can't simply initialize it to NULL and I'm not sure if casting NULL(which can be 0 or (void *)0) to the function pointer type
1
1758
by: Nacho | last post by:
Hello.. I have one problem with my reusable function to validate date.. I want to use this function to all my web project no validate date, but It's works fine if I have one textbox to validate in the same form, If I have two textbox the return doesn't works correctly.. how can I do this? if (document.Form1.TxtFechaIng.value!=''){
3
2607
by: dice | last post by:
Hi, In order to use an external api call that requires a function pointer I am currently creating static wrappers to call my objects functions. I want to re-jig this so I only need 1 static wrapper function. I would prefer to be able to pass the member function as a void* to the static wrapper but I suspect this may not even be possible. Another solution would be option 2 below but I can't figure out the syntax to call obj->*pFn(). ...
3
3052
by: ryan.mitchley | last post by:
Hi all I have a class (cPort) that is designed to receive objects and, depending on the type, call a handler (callback) in any descendant of a cProcessBlock class. Callback functions take a shared_ptr<cBaseas a parameter, and return void. The code was working fine, although I have encountered problems (under a Microsoft compiler, of course - VC 8.0) when I attempt to add callbacks to a class with multiple inheritance. I hate multiple
10
2358
by: Constantine AI | last post by:
Hi i am having a little problem with an equation function that was created from all your help previously. The function works fine itself but with a small glitch within it. Here is the function code. Public Function fCalcEquation(strEquation As String) As Long Dim MyDB As DAO.Database Dim rstParameters As DAO.Recordset Dim intParamPosition As Integer Dim strParameter As String Dim strValue As String
0
7965
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8271
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8380
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8031
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8258
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6686
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5426
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3881
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
1231
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.