Solved

Do While Not .EOF

Posted on 2006-11-28
5
1,194 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
5 Comments
 
LVL 27

Accepted Solution

by:
Ark earned 250 total points
Comment Utility
'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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
so why only grade it as a B?

AW
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

771 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now