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!

Problem With IF Statament nested with a SELECT CASE statement 1

Status
Not open for further replies.

ooch1

MIS
Nov 4, 2003
190
GB
Hi guys,

I'm sure one of you wizards will be able to let me know what i'm doing wrong!

Basically, i'm trying to populate certain start dates, based upon which date is populated and whether the F flag is set to true.

The section of code below is part of a larger if statement (propbably not the most efficient piece of code, but it is all i know)

To give you a further bit of background i am comparing 2 recordsets (rs and rs2) against each other, based upon the differences (M number for example) then the code decides on whether to populate the Effective From Date with either the historic Eff from Date of the Transco Start Date ( Based on whichever is not null)

Code:
ElseIf (M = M2 And ((rs.AbsolutePosition + 1) = rsEnd) And E2 = "00:00:00") Then
            Select Case F: _
                Case Is = True: _
                    rs2.Fields("effective from date")     
                    = Edt: rs2.Update: rs2.MoveLast: _
  [b][COLOR=red] Case Is = False: _
                    If rs![Effective From Date].Value
                    <> "00:00:00" Then 
                    rs2.Fields("effective from date") 
                    = rs![Effective From Date].Value
                    ElseIf rs![Effective From Date].Value
                     = "00:00:00" Then 
                    rs2.Fields("effective from date") = rs!
                    [Transco Start Date].Value:[/color][/b]
                rs2.Update: rs2.MoveLast: _
            End Select

When the code is as above it highlights the SELECT statement down to the IF line as red, so this obviously is incorrect. If i put underscores after the THENs, then this looks ok, but then errors on exectution at the ELSEIF line, stating that "Else Without If".

I'm hoping that i have explained myself ok. I sure that there is quite a simple answer, even if it is that you cannot have an IF statement nested as part of a SELECT statement.

Look forward to hearing from you guys.

OOch
 
You have syntax issues with Select Case and If instructions.
Feel frre to play with the F1 key when the cursor is inside the Case word in your code.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Use:

[tt]select case F
case true
' true part
case else
' will be the false part
if strSomevariable = "something" then
' true part
else
' false part
end if
end select[/tt]

That's a naming convention making it difficult to understand the code later on

Roy-Vidar
 
Thanks RoyVidar, that (plus a little tinkering) has managed to reslove this little issue.

PHV - Not to sure whether that was intended sarcasm, or me just taking it the wrong way, but I always try to use the help menus. However, in the case of syntax, i always find it difficult to combine different statements and the help menus do not really help me, when joining up the 'bigger picture'. Apologies if i have offended you in any way, but i am only after some help when i get stuck, which is what i thought this forum was for??

OOch
 
OOch, absolutely NO sarcasm from me to you.
In my VBA code I get the VBA help for the SELECT CASE instruction when I follow the instructions I gave you.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV - That is fine, as you are usually the one who seems to help me the most, so i guess i'm just a bit paranoid about posting what are possibly inane questions.

OOch
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top