Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SubForm Question 1

Status
Not open for further replies.

TMRO

Technical User
Jan 10, 2003
140
0
0
CA
Hi everybody!

I have a main form (unbound) with a comboxbox.
In the main form I have a subform which will bring values form a table realted to the value selected in the combox.

How do I populate the subform since I receive errors on this line:

Private Sub MainCombo_AfterUpdate()
Dim strSQL As String
strSQL = "SELECT * FROM Employee WHERE AID = " & _
Me!AID.Column(0)

Forms![frmMainForm]![frmSubForm].RowSource = strSQL
'this is the error line
End Sub

Thanks a lot,
TMRO
 
If aid is numeric, this should fix it:
Forms!frmMainForm!frmSubForm.form.RowSource = strSQL

If it's text, you'll also have to do this:
strSQL = "SELECT * FROM Employee WHERE AID = '" & _
Me!AID.Column(0) & "'"

Also, it's best to name your controls differently from your fields, so that there's no chance of Access getting confused. And, there's no need to refer explicitly to column(0), as that's the default. I'd actually rewrite that line to this:
strSQL = "SELECT * FROM Employee WHERE AID = '" & _
Me!cmbAID & "'"
(changing the name of the control to indicate that it's a combo box).

Jeremy
=============
Jeremy Wallace
AlphaBet City Dataworks

Take a look at the Developers' section of the site for some helpful fundamentals.
 
Thanks for the answer. Still I'm getting this error:
on the line
Forms!frmMainForm!frmSubForm.form.RowSource = strSQL
and it says:
Application - defined or object defined error

Do you know why?

Thanks again,
TMRO
 
A form doesn't have a RowSource property. You should be using the RecordSource property of the form. Change the code to:
Forms!frmMainForm!frmSubForm.Form.RecordSource = strSQL

That should do it for you
 
Thanks Tonto44. This solved my problem!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top