Update data on subform

ingrid

Registered User.
Local time
Today, 18:42
Joined
Apr 10, 2003
Messages
42
I have a form with a listbox and a subform. The subform has to be updated when the listbox is clicked.

In the subform i have a query on opening the form.
SQL = "SELECT field FROM table WHERE id = " & listbox.value
Me.Recordsource = SQL.

I tryed Forms!FormSubToezicht.repaint in the onclick of the listbox, but that doesn't work and gives an error.
 
I tryed this
Forms!FormSubToezicht.Requery
but that gives error 2450 Cannot find the form......

and I also tryed this
FormSubToezicht.Requery
but that gives error 424 Object requierd
 
the name of your subform control name is on the main forms property sheet, that is all you need

yourSubFormControlName.Requery
 
The error is gone now. But the next problem is that the data isn't updated. I think that is because the sql where the data is selected is only in the "Private Sub Form_Open(Cancel As Integer)
" and has to be somewhere else, only I don't know where.

I tryed to place the sql in the field recordsource in the propertys of the form but because there is a variable in the sql that gives an error on opening the form.
 
You should be able to set the subforms Record source to either a query or sql provided you have defined the criteria correctly, ie Forms!YourForm!YourListBox
 
What I've tryed is

Private Sub listbox_Click()
SQL = "SELECT field FROM table WHERE id =" & listbox.value
Forms!FormSubToezicht.RecordSource = SQL
End Sub

But that gives me error 2450 (Cannot find the form......
) again.
 
It works!
Thank you very very very much!!!!
 
I just found out that this also works:

Form_SubForm.RecordSource = SQL
 

Users who are viewing this thread

Back
Top Bottom