Solved

Do While Not .EOF

Posted on 2006-11-28
5
1,205 Views
Last Modified: 2012-08-13
I have a piece of code that pings a database and pulls in information. The problem is, sometimes there may not be information to pull out.

I get an error: Either BOD or EOF is true, or the current record has been deleted

I've been looking around on how to start out using it, but i still am having difficult implementing it into my program. I'm just not sure how to start it and how to end it.

My code Below:

Set t = CreateObject ("ICONICS.LoginActiveX")
Set objWSHNetwork = CreateObject("WScript.Network")

If t Is Nothing Then
      MsgBox "An error has occurred while trying to launch the login dialog."
Else
      Set conn = CreateObject("ADODB.Connection")
  Set rs = CreateObject("adodb.recordset")    <--------------------------is this correct?
      conn.ConnectionString = "driver={SQL Server};server=JSC-EC4-LENOVO2\SQLEXPRESS;uid=;pwd=;database=ASPNETDB.MDF"
      conn.Open

'Permission = "SELECT aspnet_ChamberWorkstation.Permission FROM aspnet_ChamberWorkstation INNER Join Chamber_SSATA On aspnet_ChamberWorkstation.Workstation = Chamber_SSATA.Workstation WHERE aspnet_ChamberWorkstation.Zone = 12").Fields(0).Value

--------------Do While Not rs.EOF---------> I know this is similar to what i want but i'm not sure how to create the object
            
            Permission = conn.Execute("SELECT aspnet_ChamberWorkstation.Permission FROM aspnet_ChamberWorkstation INNER Join Chamber_SSATA On aspnet_ChamberWorkstation.Workstation = Chamber_SSATA.Workstation WHERE aspnet_ChamberWorkstation.Zone = 12").Fields(0).Value

            If Permission = 0 Then

                  t.LoginUser "ADMINISTRATOR", "#testing"
                  result2 = conn.Execute ("UPDATE chamber_SSATA SET Status = 1 WHERE chamber_SSATA.workstation = '" & objWSHNetwork.ComputerName & "'")                              


            End If

            If permission = 1 Or permission = 2 Then

                  Permission = conn.Execute("SELECT aspnet_ChamberWorkstation.Permission FROM aspnet_ChamberWorkstation INNER Join Chamber_SSATA On aspnet_ChamberWorkstation.Workstation = Chamber_SSATA.Workstation WHERE aspnet_ChamberWorkstation.Zone = 12 AND RTRIM(aspnet_ChamberWorkstation.Workstation) = '" & objWSHNetwork.ComputerName & "'").Fields(0).Value

                        Select Case Permission
            
                              Case 0
                                    t.LoginUser "ADMINISTRATOR", "#testing"
                                    result2 = conn.Execute ("UPDATE chamber_SSATA SET Status = 1 WHERE chamber_SSATA.workstation = '" & objWSHNetwork.ComputerName & "'")                              
            
                              Case 1
                                    result1 = conn.Execute ("Select aspnet_ChamberWorkstation.Zone, aspnet_ChamberWorkstation.Permission, LTRIM(RTRIM(aspnet_ChamberWorkstation.Workstation)), Chamber_SSATA.Status FROM aspnet_ChamberWorkstation INNER Join aspnet_ZoneChamber On aspnet_ChamberWorkstation.Zone = aspnet_ZoneChamber.Zone INNER Join Chamber_SSATA On LTRIM(RTRIM(aspnet_ChamberWorkstation.Workstation)) = LTRIM(RTRIM(Chamber_SSATA.Workstation)) WHERE aspnet_ChamberWorkstation.Zone = 12 AND LTRIM(RTRIM(aspnet_ChamberWorkstation.Workstation)) = '" & objWSHNetwork.ComputerName & "'").Fields(2).value

                                    If result1 = objWSHNetwork.ComputerName Then            
                                          t.LoginUser "TEST DIRECTOR", "#testing"
                                          result2 = conn.Execute ("UPDATE chamber_SSATA SET Status = 1 WHERE chamber_SSATA.workstation = '" & objWSHNetwork.ComputerName & "'")                              
                                    Else
                                          MsgBox("Oops, you do not have the rights to login!/nClick 'View Chamber' to get to the Control Panel")
                                    End If

                              Case 2

                                    result1 = conn.Execute ("Select aspnet_ChamberWorkstation.Zone, aspnet_ChamberWorkstation.Permission, LTRIM(RTRIM(aspnet_ChamberWorkstation.Workstation)), Chamber_SSATA.Status FROM aspnet_ChamberWorkstation INNER Join aspnet_ZoneChamber On aspnet_ChamberWorkstation.Zone = aspnet_ZoneChamber.Zone INNER Join Chamber_SSATA On LTRIM(RTRIM(aspnet_ChamberWorkstation.Workstation)) = LTRIM(RTRIM(Chamber_SSATA.Workstation)) WHERE aspnet_ChamberWorkstation.Zone = 12 AND LTRIM(RTRIM(aspnet_ChamberWorkstation.Workstation)) = '" & objWSHNetwork.ComputerName & "'").Fields(2).value

                                    If result1 = objWSHNetwork.ComputerName Then            
                                          t.LoginUser "TECHNICIAN", "#testing"
                                          result2 = conn.Execute ("UPDATE chamber_SSATA SET Status = 1 WHERE chamber_SSATA.workstation = '" & objWSHNetwork.ComputerName & "'")                              
                                    Else
                                          MsgBox("Oops, you do not have the rights to login!/nClick 'View Chamber' to get to the Control Panel")
                                    End If
            
                              Case Else
                                    MsgBox("You do not have the necessary privilages to login.")
            
                        End Select

            End If

Rs.MoveNext
Loop

            If Permission <> 0 And Permission <> 1 And Permission <> 2 Then
                  MsgBox("You do not have the necessary permission!")
            End If
            
            Set conn = Nothing                  
End If






I guess what i'm really looking for are some guidelines as to how it all works and what i have to do to get it working in my program.


Thanks,

0
Comment
Question by:NP2322
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 28

Accepted Solution

by:
Ark earned 250 total points
ID: 18032619
'Creating recordset object
Set rs = conn.Execute("SELECT aspnet_ChamberWorkstation.Permission FROM aspnet_ChamberWorkstation INNER Join Chamber_SSATA On aspnet_ChamberWorkstation.Workstation = Chamber_SSATA.Workstation WHERE aspnet_ChamberWorkstation.Zone = 12")

If rs.EOF Then
   'No records - do whatever you want, say Permission = -1
Else
   Permission=rs.Fields(0).Value
End if
0
 
LVL 11

Expert Comment

by:Dany Balian
ID: 18036022
actually before the while not eof

u check for the eof

sthg like this:

if not rs.eof then
while not eof
 'do stuff
 rs.movenext
wend
end if

hope this helps..
dan
0
 
LVL 44

Assisted Solution

by:Arthur_Wood
Arthur_Wood earned 250 total points
ID: 18036200
in your code, the variable you call Permission would be an ADODB.Recordset object:

Set t = CreateObject ("ICONICS.LoginActiveX")
Set objWSHNetwork = CreateObject("WScript.Network")

If t Is Nothing Then
     MsgBox "An error has occurred while trying to launch the login dialog."
Else
     Set conn = CreateObject("ADODB.Connection")
  Set rs = CreateObject("adodb.recordset")    <--------------------------is this correct?
     conn.ConnectionString = "driver={SQL Server};server=JSC-EC4-LENOVO2\SQLEXPRESS;uid=;pwd=;database=ASPNETDB.MDF"
     conn.Open
     set Persmission = CreatObject("ADODB.Recordset")
'Permission = "SELECT aspnet_ChamberWorkstation.Permission FROM aspnet_ChamberWorkstation INNER Join Chamber_SSATA On aspnet_ChamberWorkstation.Workstation = Chamber_SSATA.Workstation WHERE aspnet_ChamberWorkstation.Zone = 12").Fields(0).Value
         
          Persmission.Open("SELECT aspnet_ChamberWorkstation.Permission FROM aspnet_ChamberWorkstation INNER Join Chamber_SSATA On aspnet_ChamberWorkstation.Workstation = Chamber_SSATA.Workstation WHERE aspnet_ChamberWorkstation.Zone = 12", conn)

Do while Not Permission.EOF
          If Permission("Persmission") = 0 Then

and so on.

AW
0
 

Author Comment

by:NP2322
ID: 18040404
Hey fellas, i appreciate the help. Since I used concepts from both of your posts, i decided to award both of you points evenly.

Your prompt responses help me out big time.
0
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 18040907
so why only grade it as a B?

AW
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

736 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question