Problem with code loading form/recordset

G

Guest

My boss asked me to design a form modeled after something in an Access 2000
handbook. I have done this I think, but when the user makes their selection,
Access becomes "Non Responding" and the cpu usage goes to 100%. Would
someone mind looking at the code, please? It is a very basic search and fill
in the field form.

This is where I think it locks:

Public Function Load() As Boolean
Dim rst As ADODB.Recordset

On Error GoTo HandleErrors

Set rst = New ADODB.Recordset
rst.Open "Select * from tblCourse Where ID = " & Me.Title,
Application.CurrentProject.Connection
With rst
If Not .EOF Then
mstrTitle = !Title
mstrVersion = !Version
mlngCIC_Type = !CIC_Type
mlngCIC_Num = !CIC_Num
mlngCourseNum = !CourseNum
mlngHours = !Hours
mlngDays = !Days
mstrClearance = !Clearance
mstrPrice = !Price
mlngRole = !Role
mlngVendor = !Vendor
mfQual = !Qual
mfPPE = !PPE
mstrAbstract = !Abstract
mlngCourseID = !ID
End If
End With
Load = True

ExitHere:
If Not rst Is Nothing Then rst.Close
Set rst = Nothing
Exit Function

HandleErrors:
Load = False
Resume ExitHere
End Function
 
P

PC Datasheet

Load is a reserved word and should not be used as a name of a function.
Change the function name to something else and see if you still have the
same problem.
 
G

Guest

Thank you. I don't believe that is the answer as this section of the code is
basically the same code as what the developers handbook uses with changes to
reflect the differences in fields.

from the handbook:

Public Function Load() As Boolean
Dim rst As ADODB.Recordset

On Error GoTo HandleErrors

Set rst = New ADODB.Recordset
rst.Open "Select * from tblCats WHERE ID = " & Me.ID, _
Application.CurrentProject.Connection
With rst
If Not .EOF Then
mstrName = !Name
mdatBirthdate = !Birthdate
mstrSex = !Sex
mstrBreed = !Breed
mstrColor = !Color
mfNeutered = !Neutered
mlngID = !ID
End If
End With
Load = True

ExitHere:
If Not rst Is Nothing Then rst.Close
Set rst = Nothing
Exit Function

HandleErrors:
Load = False
Resume ExitHere
End Function

What I am trying to do:

Public Function Load() As Boolean
Dim rst As ADODB.Recordset

On Error GoTo HandleErrors

Set rst = New ADODB.Recordset
rst.Open "Select * from tblCourse Where ID = " & Me.CourseID,
Application.CurrentProject.Connection
With rst
If Not .EOF Then
mstrTitle = !Title
mstrVersion = !Version
mlngCIC_Type = !CIC_Type
mlngCIC_Num = !CIC_Num
mlngCourseNum = !CourseNum
mlngHours = !Hours
mlngDays = !Days
mstrClearance = !Clearance
mstrPrice = !Price
mlngRole = !Role
mlngVendor = !Vendor
mfQual = !Qual
mfPPE = !PPE
mstrAbstract = !Abstract
mlngCourseID = !ID
End If
End With
Load = True

ExitHere:
If Not rst Is Nothing Then rst.Close
Set rst = Nothing
Exit Function

HandleErrors:
Load = False
Resume ExitHere

It seems to lock up at Me.CourseID. The original author used ID both as a
field and a variable which makes it difficult for me to translate. I've
tried Me.ID and that locks it up completely. I am grateful for any
assistance.
 
P

PC Datasheet

The handbook for which version of Aceess and what page?

Steve
PC Datasheet

PS I assume you mean Getz's Developer's Handbook.
 
G

Guest

The 2000 handbook, Chapter 3, the form is cats, and I can not give you the
page because my boss is out for the week. However, the code came from
samples provided with the book. I can include the entire code from both if
you like
 
P

Penguin

Just a thought but try this:

rst.Open "Select * from tblCats WHERE [ID] = '" & Me.ID & "'"

Using a ' character before the " and a ending like " ' "
 
Top