problem with recordset

B

bob

When I am running the code below I am getting the
following error....

Run-time error "3265"
Item not found in this collection.

The message says...
An attempt to reference a name in a collection failed.

Possible causes:
1)the object doesn't exist in this collection. Make sure
that the object is
appended to collection before referencing it.
2)There is more than one object with this name in this
collection; using
its
name with this name is an ambiguous reference. reference
the object by its
original position in the collection for e.g.. recordsets
(3)).

Code..........


private sub command 46_click()
Dim rs As DAO.Recordset
Dim db As DAO.Database ' for insert queries
Dim strsql As String

Set db = CurrentDb
Set rs = Me.RecordsetClone

With rs

If .RecordCount <> 0 Then .MoveFirst

Do Until .EOF

strsql = _
"INSERT INTO tblAttendance " & _
"(StudentClockNum, ProgramCode,
CourseNum, " & _
"LoginTime, Exempt, SHours) " & _
"VALUES (" & _
"'" & !studentclocknumber & "', " & _
"'" & !ProgCode & "', " & _
"'" & !CNum & "', " & _
Format(!Login, "\#mm/dd/yyyy
hh:nn:ss\#") & ", " & _
!Check54 & "," & _
!THours & ")"

' Uncomment if needed for debugging:
Debug.Print strsql

db.Execute strsql, dbFailOnError

.MoveNext
Loop

End With

Set rs = Nothing
Set db = Nothing
End Sub
 
J

John Vinson

When I am running the code below I am getting the
following error....

Run-time error "3265"
Item not found in this collection.

The message says...
An attempt to reference a name in a collection failed.

What line is highlighted, if any? Can you step through the code and
pin down the error message if not? Have you used Tools... References
to be sure that the DAO object library is checked?
 
V

Van T. Dinh

(guessing only).

Since you used "With rs", the following expressions

!studentclocknumber
!ProgCode
!CNum
!Login
!Check54
!THours

refer to the Fields in the Recordset. Do you have these
Fields in your Recordset "rs".

My guess is that you actually want to refer to the
Controls on the Form and (since you used "With rs"), you
need to use the in-context Form qualifier "Me" on the
above expressions.

HTH
Van T. Dinh
MVP (Access)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top