Hi All,
I've been using this code for years without problems (or so I think). I've added another table to my array and incremented my variable. When I step through the module, sqlstr returns a rec for tblFamily but the delete statement doesn't delete the record.
I've copied both sqlstr and sqlstr1 to a query to make sure they work--they do.
If I have an array of 4 tables, then loop through those tables--shouldn't my count go from 0 to 3? Please see my code below:
...
If formname.Name = "Neighborhood Input Form" Then
table(0) = "tblPhone"
table(1) = "tblTeenJobs"
table(2) = "tblPeople"
table(3) = "tblFamily"
Else
Exit Function
End If
For x = 0 To 3
'the following query shows all of the people living at the address
sqlstr = "SELECT tblFamily.FamilyID, tblPeople.PeopleID " & _
"FROM tblFamily INNER JOIN tblPeople ON tblFamily.FamilyID = " & _
"tblPeople.FamilyID " & _
"WHERE (((tblPeople.FamilyID)=" & FamilyID & "));"
Set db = CurrentDb
Set rs = db.OpenRecordset(sqlstr)
Do Until rs.EOF
If rs.RecordCount > 0 Then
PersonNumber = rs(1)
'this query deletes all of the people at an address for the above listed tables
sqlstr1 = "DELETE * " _
& " FROM " & table(x) _
& " WHERE " & Identifier & " = " & PersonNumber 'these are passed through the function
db.Execute sqlstr1
End If
rs.MoveNext
Loop
Next x
...
Thanks for any suggestions you can offer
I've been using this code for years without problems (or so I think). I've added another table to my array and incremented my variable. When I step through the module, sqlstr returns a rec for tblFamily but the delete statement doesn't delete the record.
I've copied both sqlstr and sqlstr1 to a query to make sure they work--they do.
If I have an array of 4 tables, then loop through those tables--shouldn't my count go from 0 to 3? Please see my code below:
...
If formname.Name = "Neighborhood Input Form" Then
table(0) = "tblPhone"
table(1) = "tblTeenJobs"
table(2) = "tblPeople"
table(3) = "tblFamily"
Else
Exit Function
End If
For x = 0 To 3
'the following query shows all of the people living at the address
sqlstr = "SELECT tblFamily.FamilyID, tblPeople.PeopleID " & _
"FROM tblFamily INNER JOIN tblPeople ON tblFamily.FamilyID = " & _
"tblPeople.FamilyID " & _
"WHERE (((tblPeople.FamilyID)=" & FamilyID & "));"
Set db = CurrentDb
Set rs = db.OpenRecordset(sqlstr)
Do Until rs.EOF
If rs.RecordCount > 0 Then
PersonNumber = rs(1)
'this query deletes all of the people at an address for the above listed tables
sqlstr1 = "DELETE * " _
& " FROM " & table(x) _
& " WHERE " & Identifier & " = " & PersonNumber 'these are passed through the function
db.Execute sqlstr1
End If
rs.MoveNext
Loop
Next x
...
Thanks for any suggestions you can offer