If statments problems in VB6

Hi guys i have something weird happening here and i dont know why, io have done this kind of this 100 times before and never had a issue.

Software is VB6
Database is MSDB

what i have is two if statements (at the moment there is going to be a lot more) if i select the if that matches the first if there is no problem and it works fine, but if i select the if that matches the 2nd one i get an error __ run-time error '5'; in valid procedure call or argument __ i have swoped there order in the code then the one that didnt work works, when i hit debug the it does to the start of the first if statment.  The code is below,  knowing me it is something dumb that i have done

Private Sub Archivedate_Click()
history.ListItems.Clear
connect
      Dim rs As New ADODB.Recordset
      Dim sql As String
      Dim objItem As ListItem
           
       
If sfmt.Tag = True Then
sql = "select * from [Assessment Records] where [date]=#" & Format(Archivedate, "dd/mmm/yyyy") & "#  and  [member id] = " & mid.Caption
Debug.Print sql
cnn1.Open
rs.Open sql, cnn1, adOpenDynamic, adLockPessimistic
   adate.Caption = Format((Archivedate.Text), "DDDD DD/mmm/YYYY")
       
                   Set objlst = history.ListItems.Add(, , bicepssfm.Caption)
                   objlst.SubItems(1) = rs.Fields("bicepssfm")
                   Set objlst = history.ListItems.Add(, , Tricep.Caption)
                   objlst.SubItems(1) = rs.Fields("tricepsfm")
                   Set objlst = history.ListItems.Add(, , subscapular.Caption)
                   objlst.SubItems(1) = rs.Fields("subscapular")
                   Set objlst = history.ListItems.Add(, , supraiiiliac.Caption)
                   objlst.SubItems(1) = rs.Fields("SUpRAiI  iLIAC")
                   history.Visible = True
                   rs.Close
                   cnn1.Close
                   Else
If psword.Tag = True Then
cnn1.Open
sql = "select * from [Assessment Records] where [date]=#" & Format(Archivedate, "dd/mmm/yyyy") & "#  and  [member id] = " & mid.Caption
Debug.Print sql
rs.Open sql, cnn1, adOpenDynamic, adLockPessimistic
       adate.Caption = Format((Archivedate.Text), "DDDD DD/mmm/YYYY")
                    Set objlst = history.ListItems.Add(, , Label55.Caption)
                   objlst.SubItems(1) = rs.Fields("cv capacity")
                   Set objlst = history.ListItems.Add(, , Label54.Caption)
                   objlst.SubItems(1) = rs.Fields("FLEXIBILITY SCORE")
                   Set objlst = history.ListItems.Add(, , Label59.Caption)
                   objlst.SubItems(1) = rs.Fields("ABDOMINAL STRENGTH")
                   Set objlst = history.ListItems.Add(, , Label74.Caption)
                   objlst.SubItems(1) = rs.Fields("CHEST STRENGTH")
                   Set objlst = history.ListItems.Add(, , Label57.Caption)
                   objlst.SubItems(1) = rs.Fields("LEG STRENGTH")
                   Set objlst = history.ListItems.Add(, , Label52.Caption)
                   objlst.SubItems(1) = rs.Fields("HANDGRIP STRENGTH L")
                   Set objlst = history.ListItems.Add(, , Label58.Caption)
                   objlst.SubItems(1) = rs.Fields("HANDGRIP STRENGTH R")
                    Set objlst = history.ListItems.Add(, , Label50.Caption)
                   objlst.SubItems(1) = rs.Fields("SCAPULAR STRENGTH")
                   Set objlst = history.ListItems.Add(, , Label65.Caption)
                   objlst.SubItems(1) = rs.Fields("Back STRENGTH")
                   history.Visible = True
                   rs.Close
                   cnn1.Close
                   Else

         
' rs.Close
'cnn1.Close

End If
End If
End Sub
awolarczukAsked:
Who is Participating?
 
sirbountyConnect With a Mentor Commented:
True is typically used for boolean values...

Dim blnTest As Boolean

If blnTest Then
or
If blnTest=True Then

are both valid, because the boolean can only be True or False

However, you're using a string value for the Tag property (which won't accept a boolean), so you have to specify that it's a string, by enclosing it in quotes in your test... if control.Tag="Some value" 'could be anything - I usually drop a numeric character in there, rather than text....

Glad that worked for you! :^)
0
 
sirbountyCommented:
The things that jump out at me (and admittedly, it's late for me... :)

Combine this:
                 Else
If psword.Tag = True Then

into                  

ElseIf psword.Tag = True Then

Also - mid.Caption - is that a control name?  It's also a function, so perhaps alter that to something else...

To clarify - you're saying
If A Then
 'this works
elseif B Then
 'this doesn't
End If

Yet,
If B Then
 'this works
elseif A Then
 'this doesn't
End If

Is that right?
0
 
awolarczukAuthor Commented:
yep i am saying if a then fo this if b then do this and then it will get to if c do this in each case it only does one of then, i have change it to else if and it didnt make a difference
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
sirbountyCommented:
Oh, well that changes things slightly, I think...
Let's weed out everything except your comparisons...
       
If sfmt.Tag = True Then
 'if sfmt.Tag is "True" then process this code...
  Else  'If it's not then test the code here
    If psword.Tag = True Then
       'If psword.Tag is "True" then process this code
    Else
       'otherwise process this
    End If
End If

So, I'm not sure that the comparisons are setup properly.
Try it this way

       
If sfmt.Tag = True Then
 'A
ElseIf psword.Tag = True Then
 'B
Else
 'C (will only process if A & B are not True)
End If
0
 
awolarczukAuthor Commented:
yea almost when i am in the software i am going to be calling a,b or c none of them can be on at the same timebut any of them can be selected at anytime, what you have above is what i already am doing
0
 
awolarczukAuthor Commented:
Private Sub Archivedate_Click()
history.ListItems.Clear
connect
      Dim rs As New ADODB.Recordset
      Dim sql As String
      Dim objItem As ListItem
           
       
If sfmt.Tag = True Then
sql = "select * from [Assessment Records] where [date]=#" & Format(Archivedate, "dd/mmm/yyyy") & "#  and  [member id] = " & mid.Caption
Debug.Print sql
cnn1.Open
rs.Open sql, cnn1, adOpenDynamic, adLockPessimistic
   adate.Caption = Format((Archivedate.Text), "DDDD DD/mmm/YYYY")
       
                   Set objlst = history.ListItems.Add(, , bicepssfm.Caption)
                   objlst.SubItems(1) = rs.Fields("bicepssfm")
                   Set objlst = history.ListItems.Add(, , Tricep.Caption)
                   objlst.SubItems(1) = rs.Fields("tricepsfm")
                   Set objlst = history.ListItems.Add(, , subscapular.Caption)
                   objlst.SubItems(1) = rs.Fields("subscapular")
                   Set objlst = history.ListItems.Add(, , supraiiiliac.Caption)
                   objlst.SubItems(1) = rs.Fields("SUpRAiI  iLIAC")
                   history.Visible = True
                   rs.Close
                   cnn1.Close
                 
ElseIf psword.Tag = True Then
cnn1.Open
sql = "select * from [Assessment Records] where [date]=#" & Format(Archivedate, "dd/mmm/yyyy") & "#  and  [member id] = " & mid.Caption
Debug.Print sql
rs.Open sql, cnn1, adOpenDynamic, adLockPessimistic
       adate.Caption = ""
       adate.Caption = Format((Archivedate.Text), "DDDD DD/mmm/YYYY")
                    Set objlst = history.ListItems.Add(, , Label55.Caption)
                   objlst.SubItems(1) = rs.Fields("cv capacity")
                   Set objlst = history.ListItems.Add(, , Label54.Caption)
                   objlst.SubItems(1) = rs.Fields("FLEXIBILITY SCORE")
                   Set objlst = history.ListItems.Add(, , Label59.Caption)
                   objlst.SubItems(1) = rs.Fields("ABDOMINAL STRENGTH")
                   Set objlst = history.ListItems.Add(, , Label74.Caption)
                   objlst.SubItems(1) = rs.Fields("CHEST STRENGTH")
                   Set objlst = history.ListItems.Add(, , Label57.Caption)
                   objlst.SubItems(1) = rs.Fields("LEG STRENGTH")
                   Set objlst = history.ListItems.Add(, , Label52.Caption)
                   objlst.SubItems(1) = rs.Fields("HANDGRIP STRENGTH L")
                   Set objlst = history.ListItems.Add(, , Label58.Caption)
                   objlst.SubItems(1) = rs.Fields("HANDGRIP STRENGTH R")
                    Set objlst = history.ListItems.Add(, , Label50.Caption)
                   objlst.SubItems(1) = rs.Fields("SCAPULAR STRENGTH")
                   Set objlst = history.ListItems.Add(, , Label65.Caption)
                   objlst.SubItems(1) = rs.Fields("Back STRENGTH")
                   history.Visible = True
                   rs.Close
                   cnn1.Close
               

         
' rs.Close
'cnn1.Close

End If
End Sub
0
 
sirbountyCommented:
Mid.Caption
Does this not throw an error?  It does on my end...what is Mid?
0
 
sirbountyCommented:
Also, your last post - it doesn't contain the fall out Else statement...
If A Then
ElseIf B Then
Else 'presumably C
End If

Also - your test for the Tag property...they're not boolean.  I assume you mean to enclose these in quotes:

If sfmt.Tag = "True" Then
0
 
sirbountyCommented:
This is the output from the code below...

sfmt.tag is true
psword.tag is true
Neither tags are True


Sub form_Load()
sfmt.Tag = "True"
Archivedate_Click
sfmt.Tag = ""
psword.Tag = "True"
Archivedate_Click
psword.Tag = ""
Archivedate_Click
End
End Sub

Private Sub Archivedate_Click()
If sfmt.Tag = "True" Then
  sql = "select * from [Assessment Records] where [date]=#" & Format(Archivedate, "dd/mmm/yyyy") & "#  and  [member id] = " '& Mid.Caption
  Debug.Print "sfmt.tag is true"
ElseIf psword.Tag = "True" Then
  sql = "select * from [Assessment Records] where [date]=#" & Format(Archivedate, "dd/mmm/yyyy") & "#  and  [member id] = " '& Mid.Caption
  Debug.Print "psword.tag is true"
Else
  Debug.Print "Neither tags are True"
End If
End Sub
0
 
awolarczukAuthor Commented:
ok i got it working it was the fact that i didnt have the "" are the true, can you please tell me whys this is so
0
 
sirbountyCommented:
Not sure why this was graded a "B".  What was missing from my answer?
0
 
awolarczukAuthor Commented:
I didnt think it wasa bad answer but i didnt think it was the best one that i have got on the site, even though the elseif cleaned up the code, it wasnt needed to fix the problem that i was having, the fix for that was just the "" and i feel that it took some time to get to this Answer, i am sorry for the grade
0
All Courses

From novice to tech pro — start learning today.