Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Do While Not .EOF

Posted on 2006-11-28
5
Medium Priority
?
1,211 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 750 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 750 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

Technology Partners: 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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

636 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