Discussion Locked

Access 2002 Compile Error

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have received some help with my problem as you can see below after the original question but I continue to receive a Compile Error: User defined type-not defined when I click on the command button "next" on form 1. The code on the next form was entered as suggested below in the reply. It highlights the "Dim rs As DAO.Recordset" and I get the Compile error above. Can you please help me it would be greatly appreciated.

Reply 1:
If I understand you correctly, you need to pass the primary keyfield from one form to another, then force the second form to jump to that correct record. You can pass the key field to the next form using the OpenArgs property,
e.g.
DoCmd.OpenForm "next form",acNormal,,,,, Me![key field]

In the OnLoad event of the next form,

Dim rs As DAO.Recordset

Set rs = Me.RecordsetClone
rs.FindFirst "[key field] = " & Me.OpenArgs
If Not rs.NoMatch Then

Me.Bookmark = rs.Bookmark

End If

Set rs = Nothing

--
Hope this helps
Tony Oakley (MVP)2nd REPLY:
You place that code in your command button's onclick event procedure passing the information about the current record you are currently processing to the next form.

DoCmd.OpenForm "[next form]", acNormal,,,,,Me![primary key field]
In the Onload event procedure of the next form, you go forward (or back) to the record you are processing in your previous form. For example, you are already at the record 3, and when you click on the next button, you want the next form to show up records for record 3. You do this by:

Dim rs as DAO.Recordset

set rs = Me.RecordsetClone
rs.FindFirst "[primary key field]=" & Me.OpenArgs
If Not rs.NoMatch then

me.bookmark = rs.bookmark

end if

set rs = nothing

The findfirst method above finds record 3 and set's the current bookmark to that record for the next record.

3 replies

by crowmoor

Check you referenses in the modules. Probably you have a reference that is missing(marked missing) or you lack a reference to ADO or DAO. Scroll down in the list and check a likly file and try to compile again. If you get an error again then it was the wrong file. The file will be namned something with DAO or ADO. Probably Microsoft DAO or something.

Good luck!

Crowmoor

by carljohnman

Thank you very much for your help. It is greatly appreciated. Dirk Goldgar replied to my question in another site with these specific instructions,which it appears you were leading me that way. Thanks.
It appears that you need to add a reference tothe Microsoft DAO 3.6 Object Library. With the code module open in the VB Editor, click Tools-References..., locate that reference in the list, and put a check mark in the box next to it.

This discussion is closed to new replies.