Refreshing SubForm (1 Viewer)

jmmm

Registered User.
Local time
Tomorrow, 05:21
Joined
Aug 3, 2009
Messages
13
Hope I can explain this properly! Please bear with me..
I have a SubForn based on a Table, which is empty.
The main form lets me input a set of data. I then open a recordset
to the aforementioned table, and populate it with .Addnew and .Update.

My aim is to have the subForm show this data - as if it were there when
the Form opened. It doesn't.

So should I close and re-open the Subform? Or use 'Refresh'. Oer some other method?

Thanks.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 10:21
Joined
Aug 30, 2003
Messages
36,127
Requery would be the appropriate method.
 

jmmm

Registered User.
Local time
Tomorrow, 05:21
Joined
Aug 3, 2009
Messages
13
The command is, from help,
DoCmd.Requery [controlname]

The name of my 'control' is tblLPtsubform
but the instruction -

DoCmd.Requery ("tblLPtsubform")

brings up error

Run-time error '2109':
There is no field named 'tblLPtsubform' in the current record.

Should I use a Control Data type e.g.

Dim MyControl As Control
Set MyControl = Forms!frmLPWork!tblLPtsubform
DoCmd.Requery MyControl.Name

I'm completely guessing, but that similar to the Help example.
 

ted.martin

Registered User.
Local time
Today, 17:21
Joined
Sep 24, 2004
Messages
743
try this:

Forms![F-Mainform].[SF-Subform].[Form].requery
 

MaZeWorX

New member
Local time
Today, 13:21
Joined
Jul 1, 2009
Messages
9
Try tblLPtsubform.Requery assuming this is the name of your subform ... requeried from the form within your subform otherwise use the above syntax
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 10:21
Joined
Aug 30, 2003
Messages
36,127
Here's an example from a db of mine:

Forms!frmMap.frmCarsInZone.Requery
 

jmmm

Registered User.
Local time
Tomorrow, 05:21
Joined
Aug 3, 2009
Messages
13
Thanks for all the advise. Sadly I still can't get requery to do anything but give an error. Here's the three syntaxes and the errors -

Forms!frmLPWork.tblLPtsubform.Requery
Run-time error '2465':
Application-defined or object-defined error

Forms![frmLPWork].[tblLPtsubform].[Form].Requery
Run-time error '2465':
Microsoft Access can't find the field 'tblLPtsubform' referred to in your expression.

tblLPtsubform.Requery
Compile error:
Variable not defined

More info - my Form Name is frmLPWork
SubForm name is tblLPtsubform

I tried the above commands both in a Module and in code behind a subform called
"frmLP". This has the command button which does some stuff, then a requery.

Maybe the requery code has to be somewhere else ?

When it says 'Access can't find the field 'tblLPtsubform'' why is it calling my subForm a field ?

All very puzzling... I do have it working by Closing the Form and immediately Opening it again. Seems the wrong approach though.
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 10:21
Joined
Aug 30, 2003
Messages
36,127
What's actually needed is the name of the subform control in the main form, if it's different than the name of the subform itself. My guess is that the name of the control is something other than tblLPtsubform.
 

jmmm

Registered User.
Local time
Tomorrow, 05:21
Joined
Aug 3, 2009
Messages
13
Aha! Paul - many thanks, you are indeed right! But I don't feel too much of a goof, somehow a "1" had been appended to the name without me realising.

Now working nicely, and more logically. Thanks again :)
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 10:21
Joined
Aug 30, 2003
Messages
36,127
No problem jmmm, glad we got it sorted out.
 

Users who are viewing this thread

Top Bottom