K
-Karl
See code below, My 2nd recordset is causing me a endless loop. I only
have 3 entries in a test Db that I am trying it on yet I get this
endless loop? Any thoughts?
Private Sub Command4_Click()
' Dimension Variables
'----------------------------------------------------------
Dim rsNewTest As DAO.Recordset
Dim dbl As DAO.Database
Set dbl = CurrentDb()
Dim sqlNewTest As String
sqlNewTest = "Select ID, Site from Sites"
Set rsNewTest = dbl.OpenRecordset(sqlNewTest, dbOpenDynaset)
Do Until rsNewTest.EOF
'Display Table Names??
'For Counter = 0 To rsNewTest.Fields.Count - 1
' MsgBox rsNewTest.Fields(Counter).Name
'Next
'Does the record already exist?
If Me.Text2 = rsNewTest.Fields("Site") Then
'MsgBox rsNewTest.Fields("ID") & " " & rsNewTest.Fields
("Site")
SiteID = rsNewTest.Fields("ID")
'Populate the combobox based on the Site name
sqlNewTest1 = "Select Server from Servers where SiteID
= " & rsNewTest.Fields("ID")
Set rsNewTest1 = dbl.OpenRecordset(sqlNewTest1,
dbOpenDynaset)
' THIS PART CREATES AN ENDLESS LOOP!!! WHY???
Do Until rsNewTest1.EOF
MsgBox rsNewTest1.Fields("Server")
MyCount = MyCount + 1
If MyCount = 5 Then
MsgBox "breaking loop"
Exit Do
End If
Loop
flag = 1
Exit Do
End If
rsNewTest.MoveNext
Loop
'If the Flag = 0 then insert the value into the table
If flag <> 1 Then
Set db = CurrentDb
db.Execute "INSERT INTO Sites (Site) VALUES ('" & Me.Text2 & "')"
'Else
'MsgBox "flag is 1"
End If
' close the recordset
dbl.Close
Set rsNewTest = Nothing
Set flag = Nothing
End Sub
have 3 entries in a test Db that I am trying it on yet I get this
endless loop? Any thoughts?
Private Sub Command4_Click()
' Dimension Variables
'----------------------------------------------------------
Dim rsNewTest As DAO.Recordset
Dim dbl As DAO.Database
Set dbl = CurrentDb()
Dim sqlNewTest As String
sqlNewTest = "Select ID, Site from Sites"
Set rsNewTest = dbl.OpenRecordset(sqlNewTest, dbOpenDynaset)
Do Until rsNewTest.EOF
'Display Table Names??
'For Counter = 0 To rsNewTest.Fields.Count - 1
' MsgBox rsNewTest.Fields(Counter).Name
'Next
'Does the record already exist?
If Me.Text2 = rsNewTest.Fields("Site") Then
'MsgBox rsNewTest.Fields("ID") & " " & rsNewTest.Fields
("Site")
SiteID = rsNewTest.Fields("ID")
'Populate the combobox based on the Site name
sqlNewTest1 = "Select Server from Servers where SiteID
= " & rsNewTest.Fields("ID")
Set rsNewTest1 = dbl.OpenRecordset(sqlNewTest1,
dbOpenDynaset)
' THIS PART CREATES AN ENDLESS LOOP!!! WHY???
Do Until rsNewTest1.EOF
MsgBox rsNewTest1.Fields("Server")
MyCount = MyCount + 1
If MyCount = 5 Then
MsgBox "breaking loop"
Exit Do
End If
Loop
flag = 1
Exit Do
End If
rsNewTest.MoveNext
Loop
'If the Flag = 0 then insert the value into the table
If flag <> 1 Then
Set db = CurrentDb
db.Execute "INSERT INTO Sites (Site) VALUES ('" & Me.Text2 & "')"
'Else
'MsgBox "flag is 1"
End If
' close the recordset
dbl.Close
Set rsNewTest = Nothing
Set flag = Nothing
End Sub