recordset "over" 2 forms

J

Jean-Paul

I think this is a rather basic question and difficult to explain, but
I'll try

I have this form with 1 entryfield and 1 puhbutton
In this entryfield I enter a name, or part of a name
I click the pushbutton and another form opens, based upon what I entered
in the first form
The code for the pushbutton of the first form is:

Private Sub Knop13_Click()
If IsNull(Me!Naam_lk) = False Then
If MsgBox("Je koos een naam", vbOKOnly, "Let op") Then
End If
End If

If IsNull(Me!Naam_lk) = False Then
Dim g As Form, f As Form
Dim db As Database
Set db = CurrentDb()
Dim tb As Recordset
Dim sql As String
Set g = Forms![Selectie]
DoCmd.OpenForm ("leerkrachten")
Set f = Forms![leerkrachten]
sql = "SELECT leerkrachten.* FROM leerkrachten WHERE
leerkrachten.NAAM= '" & Replace(g!Naam_lk, "'", "''") & "' ;"
Set tb = db.OpenRecordset(sql)
If tb.RecordCount = 0 Then
sql = "SELECT leerkrachten.* FROM leerkrachten WHERE
leerkrachten.Naam Like '" & "*" & Replace(g!Naam_lk, "'", "''") & "*" & "';"
Set tb = db.OpenRecordset(sql)
End If
f!nm_lk = tb!naam
f!str_lk = tb!straat
f!gem_lk = tb!plaats
f!Geb_lk = tb!geboortedatum
f!PN_lk = tb!postnummer
f!GSM_lk = tb!GSM
f!mail_lk = tb!Email
f!Synd_lk = tb!gesyndiceerd
f!Nu_lk = tb![Nu nog actief]
End If
End Sub

(I'm sure this code can be a lot better so any comment is welcome)

The newly opened form is called "leerkrachten"
Everything works just fine.
On this second form I created a pushbutton to navigate through the
recordset I created through the code above
But, when I click the pushbutton nothing happens... i have the idea I
"lost" the recordset

What am I doing wrong and how to solve this problem
Thanks you all

JP
 
Y

Yanick

I think I have a very simple solution. All you have to do is to pass
"g!Naam_lk" to the second form with the OpenArgs. You could then create the
record set in the event of your choice in your second form.

If you are not sure how to use OpenArgs, it is easy to find help on this in
MS Access built in help.
 
J

Jean-Paul

Thanks for the help...
I entered "OpenArgs" in the help... nothing found...
Your solution isn't very clear to me (sorry)
Any help is welcome
JP
 
Y

Yanick

The last parameter of the "docmd.openform" function is the OpenArgs. This
parameter can ben use to send information to the form you want to open.

You can then send information to build your recordset through the OpenArgs.

The in the FormLoad event of the form you open you can simply say :

StrVar = OpenArgs

Then build your query.

If you search for OpenArgs in this newsgroup you will find many results.
 

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