Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

-Multiple boolean tests in 1 IF statement-

Status
Not open for further replies.

Jokada

Programmer
Apr 29, 2004
24
BE
Hi i want to write an dynamic update statement
there for i need to check wether the previous coloumn values were empty. but the code never seems to get into the "if boolean or boolean or boolean or ... "
How should I write it to make it work??
If one of the booleans is true it should go in the if otherwise in the else
Thanks in advance!!!

Code:
strSqlUpdate = "UPDATE [employee2] SET "
			
If (StrComp(strVoorNaam, strVoorNaamTemp) <> 0) Then 
    boolUPDVoornaam = true
    melding = melding +1 
    strSqlUpdate = strSqlUpdate & "[VoorNaam] = " & "'"    &   strVoorNaamTemp & "'"
			
ElseIf (StrComp(strAchterNaam, strAchterNaamTemp) <> 0) Then 
	boolUPDAchterNaam = True
	melding = melding +1
	If boolUPDVoornaam Then
	 	strSqlUpdate = strSqlUpdate &  " ,  [AchterNaam] = " & "'" & strAchterNaamTemp & "'"
        Else
		 strSqlUpdate = strSqlUpdate &  " [AchterNaam] = " & "'" & strAchterNaamTemp & "'"
	End If
			
ElseIf (StrComp(strLocation, strLocationTemp) <> 0) Then
	boolUPDLocation = True 
	melding = melding +1
	If boolUPDVoornaam Or boolUPDAchterNaam Then
			    	strSqlUpdate = strSqlUpdate & " , [Location] = " & "'" & strLocationTemp & "'"
	Else
	   	strSqlUpdate = strSqlUpdate & " [Location] = " & "'" & strLocationTemp & "'"
	End If
			
ElseIf (StrComp(strKostenstelle, strKostenstelleTemp) <> 0) Then 
	boolUPDKostenstelle = True
	melding = melding +1
	If boolUPDVoornaam Or boolUPDAchterNaam Or boolUPDLocation Then
		strSqlUpdate = strSqlUpdate & " , [Kostenstelle] = " & "'" & strKostenstelleTemp & "'"
	Else
		strSqlUpdate = strSqlUpdate & " [Kostenstelle] = " & "'" & strKostenstelleTemp & "'"
	End If
			
ElseIf (StrComp(strAbteilung, strAbteilungTemp) <> 0) Then 
	boolUPDAbteilung = True
	melding = melding +1
	If boolUPDVoornaam Or boolUPDAchterNaam Or boolUPDLocation Or boolUPDKostenstelle Then
	    	strSqlUpdate = strSqlUpdate & " , [Abteilung] = " & "'" & strAbteilungTemp & "'"
	Else
		strSqlUpdate = strSqlUpdate & " [Abteilung] = " & "'" & strAbteilungTemp & "'"
	End If
			
ElseIf (StrComp(strDescription, strDescriptionTemp) <> 0) Then 
	boolUPDDescription = True
	melding = melding +1
	If boolUPDVoornaam Or boolUPDAchterNaam Or boolUPDLocation Or boolUPDKostenstelle Or boolUPDAbteilung Then
		strSqlUpdate = strSqlUpdate & " , [Description] = " & "'" & strDescriptionTemp & "'" 
	Else
		strSqlUpdate = strSqlUpdate & " [Description] = " & "'" & strDescriptionTemp & "'" 
	End If
Else
	'brauchen kein update fus dieses record
End If
			
If (melding <> 0) Then
strSqlUpdate = strSqlUpdate & " WHERE [Username] = " & "'" & strUsername & "'" 
MsgBox strSqlUpdate
iUpdate = iUpdate +1
UpdateCommand.CommandType = 1
UpdateCommand.CommandText = strSqlUpdate
UpdateCommand.Execute
melding = 0
boolUPDVoornaam = False
boolUPDAchterNaam = False
boolUPDLocation = False
boolUPDKostenstelle = False
boolUPDAbteilung = False
boolUPDDescription = False
End If
			
Else	
'nog niet 
End If
 
Anyway, testing only melding would make the code simpler.
No need of all this boolean.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
The general syntax you are looking for is:
Code:
If Test1 = Val1 Or Test2 = Val2 Or Test3 = Val3 Then
You can use parens"()" to make the intent more obvious:
Code:
If (Test1 = Val1) Or (Test2 = Val2) Or (Test3 = Val3) Then
Or for logical grouping:
Code:
If (Test1 = Val1 And Test2 = Val2) Or (Test3 = Val3) Then
In the last example, the then block will execute if Test1 AND Test2 are true OR if Test3 is true.

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
Never mind the if statements were correct but all those elseif needed to be new if statements :p
no wonder the code never enters! the other statements
Sorry that i have troubled you guys, but thanks anyway!
 
Have you get rid of the 6 spurious boolUPDxxx variables, just testing melding during the strSqlUpdate building ?

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top