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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access won't close???

Status
Not open for further replies.

pleasehelpalot

Instructor
Oct 4, 2005
92
US
I added a Function to my Application which fills a record on a form with the data from a previous record. It worked fine except when I go to exit the Application Access stays open and can't be closed. I'm forced to restart to get out of the loop.
I never had this happen before and can't figure out the connection with the Function. There is an onCurrent event that calls the function.
Does anyone understand what's going on?
 
Have you tried stepping through your code? Try setting your code to where when you do the last event, it breaks on a line in that code, so you can step through the code in order to trouble-shoot.

--

"If to err is human, then I must be some kind of human!" -Me
 
If the function uses a recordset, be sure it's always closed and released.

BTW, why not posting the code of this suspicious function ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I think the recordset is being left open but don't know how to close it.
Here is the code:
Option Compare Database

Option Explicit
Function AutoFillNewRecord(F As Form)

Dim rs As DAO.Recordset, C As Control
Dim FillFields As String, FillAllFields As Integer

On Error Resume Next

' Exit if not on the new record.
If Not F.NewRecord Then Exit Function

' Goto the last record of the form recordset (to autofill form).
Set rs = F.RecordsetClone
rs.MoveLast

' Exit if you cannot move to the last record (no records).
If Err <> 0 Then Exit Function

' Get the list of fields to autofill.
FillFields = ";" & F![AutoFillNewRecordFields] & ";"

' If there is no criteria field, then set flag indicating ALL
' fields should be autofilled.
FillAllFields = Err <> 0

F.Painting = False

' Visit each field on the form.
For Each C In F
' Fill the field if ALL fields are to be filled OR if the
' ...ControlSource field can be found in the FillFields list.
If FillAllFields Or InStr(FillFields, ";" & (C.name) & ";") > 0 Then
C = rs(C.ControlSource)
End If
Next

F.Painting = True

End Function

How and where do I close the recordset.(I don't know a lot of VB just cut and pasted from MS websight)
 
First, I'd move your recordset "setting" outside of your loop - just before the loop begins.

Second, to close and do away with the recordset....

Code:
   rs.Close
   Set rs = Nothing
End Function

--

"If to err is human, then I must be some kind of human!" -Me
 
Turns out I just needed to change C = rs(C.ControlSource)
to C = rs(C.ControlSource).value

Thanks for your response.
 
Glad it worked out.

It would still be a good idea to close and "set to nothing" the recordset at the end of your code.

--

"If to err is human, then I must be some kind of human!" -Me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top