Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening and closing record sets

Status
Not open for further replies.

Nickaroo

MIS
Mar 24, 2003
21
US
I have two tables, with a one to many relantionship. Main (Customer record) and many(billing records). Permit# as a index key

I am opening and closing the(billing table) recordset every time the Customer records moves from one to the next.


Is there a more efficient way doing this than what I have listed below?

Thanks.



Private Sub UpdateHistoryRecord(Pf As String)
Dim rst As ADODB.Recordset, countrecords As Integer
Set rst = New ADODB.Recordset
selectionrecords = "select * from history where dispos in('HE','EM')" _
& " and permit = '" & Pf & "'" & " order by datepermit"
countrecords = 1
rst.Open selectionrecords, CurrentProject.Connection, adOpenKeyset, adLockPessimistic, 1
With rst
If .RecordCount > 0 Then
.MoveFirst
While Not .EOF
.Fields("history") = countrecords
countrecords = countrecords + 1
'End If
.MoveNext
Wend
End If
End With
rst.Close
Set rst = Nothing

End Sub


Private Sub UpdateRecords_Click()
Dim rst As ADODB.Recordset, permitf As String
Set rst = New ADODB.Recordset

rst.Open "armaster", CurrentProject.Connection, adOpenKeyset, adLockPessimistic
With rst
.MoveFirst
While Not .EOF
permitf = .Fields("permit")
UpdateHistoryRecord (permitf)
.MoveNext
Wend
rst.Close
MsgBox "Sucessfull ", vbInformation, "UPDATE"

End With

Set rst = Nothing

End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top