syntax for forms in public subs ?

  • Thread starter Thread starter nickp
  • Start date Start date
N

nickp

Guest
hi, after a lot of trial and error, i hope someone can help.

I´ve got lots of similar forms which can use the same sub to fill out various controls. Calling a public sub from within the form is ok but how do if refer to the calling form in the sub.

I thought i could use the Me.controls as the form is open, but i just get errors



here´s my code:

Public Sub Fill_names_in_form(inthousenumber As Integer, strformname)

Dim db As Database
Dim counting As Integer

Set db = CurrentDb()
Set rst = db.OpenRecordset("Select * from Abfhausplan Where House like " & " '" & inthousenumber & "'")
rst.MoveLast
rst.MoveFirst


For counting = 1 To rst.RecordCount


forms!(?????????).Controls("occ" & counting) = rst!Vorname & " " & rst!Name
If rst.Klasse <> "" Then strformname.Controls("class" & counting) = "Klasse " & rst!Klasse

rst.MoveNext
Next


???
 
G'day nickp and welcome to the site.

You could try something like this: -

Forms(strformname).Controls("occ" & counting) = rst!Vorname & " " & rst!Name
or
Forms(strformname)("occ" & counting) = rst!Vorname & " " & rst!Name

Hope that helps.

Regards,
Chris.
 
Thanks Chris. it worked straight away

Regards,
Nick
 

Users who are viewing this thread

Back
Top Bottom