Requery a form from its subform, then add new

L

.Len B

I have a form with a subform with no navigation buttons.
The subform has a cmdSave button to save the detail record.
In its click event I have
If Not Me.NewRecord Then RunCommand acCmdRecordGoToNew
Me.Parent.Requery

Depending on the order of these two statements I get a
different problem.

If I use the order shown, the RecordGoToNew works but it
is effectively undone by the requery. If I add another
RecordGoToNew line I get error 2046: The command or
action 'RecordGoToNew' isn't available now.

If I switch order I receive the 2046 error.

It seems that a requery prevents the GoToNew from working.

So far I have avoided doing the requery at all but how do I
introduce it without creating a problem?
 
J

Jeanette Cunningham

The way I see it, you would requery the parent form to pick up any new
information that has been added to the table/s the parent form is based on
and then show them on the form.
If you are adding and editing information in the subform, I am not seeing
why there is a need to requery the parent form. Perhfaps there is more to
this than shown in your post.

To go to a new record in the subform, I would use code like this on the save
button
--start of sample code
If Me.Dirty Then
Me.Dirty = False
End If

DoCmd.GoToRecord , ,acNewRec
--end of sample code


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
L

.Len B

Hi Jeanette,
I indeed do have Dirty=False earlier in the code followed by a
MsgBox saying "saved" then the RunCommand acCmdRecordGoToNew.

In the bottom half of the main form I have a FlexGrid ActiveX
control which imitates an uneditable subform (datasheet) but
the height of each row varies depending on content. It is this
control that I want to update with the detail record just saved,
whilst leaving the true subform available and ready to enter a
brand new detail record. In fact the subform has no navigation
buttons so that the user cannot access earlier detail records
to edit (or even view) them.

I haven't tested the DoCmd.GoToRecord variation yet to see if
it also errors with a 2046.

--
Len
______________________________________________________
remove nothing for valid email address.
| The way I see it, you would requery the parent form to pick up any new
| information that has been added to the table/s the parent form is based
on
| and then show them on the form.
| If you are adding and editing information in the subform, I am not
seeing
| why there is a need to requery the parent form. Perhfaps there is more
to
| this than shown in your post.
|
| To go to a new record in the subform, I would use code like this on the
save
| button
| --start of sample code
| If Me.Dirty Then
| Me.Dirty = False
| End If
|
| DoCmd.GoToRecord , ,acNewRec
| --end of sample code
|
|
| Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
|
| | >I have a form with a subform with no navigation buttons.
| > The subform has a cmdSave button to save the detail record.
| > In its click event I have
| > If Not Me.NewRecord Then RunCommand acCmdRecordGoToNew
| > Me.Parent.Requery
| >
| > Depending on the order of these two statements I get a
| > different problem.
| >
| > If I use the order shown, the RecordGoToNew works but it
| > is effectively undone by the requery. If I add another
| > RecordGoToNew line I get error 2046: The command or
| > action 'RecordGoToNew' isn't available now.
| >
| > If I switch order I receive the 2046 error.
| >
| > It seems that a requery prevents the GoToNew from working.
| >
| > So far I have avoided doing the requery at all but how do I
| > introduce it without creating a problem?
| >
| > --
| > Len
| > ______________________________________________________
| > remove nothing for valid email address.
| >
| >
|
|
 
L

.Len B

| Hi Jeanette,
| I indeed do have Dirty=False earlier in the code followed by a
| MsgBox saying "saved" then the RunCommand acCmdRecordGoToNew.
|
| I haven't tested the DoCmd.GoToRecord variation yet to see if
| it also errors with a 2046.


DoCmd.GoToRecord also causes error
2105:You can't go to the specified record.

--
Len
______________________________________________________
remove nothing for valid email address.
|
| --
| Len
| ______________________________________________________
| remove nothing for valid email address.
 
J

Jeanette Cunningham

Sorry, I don't have any experience with any ActiveX controls - in fact I
stay well away from them as there can be problems with different versions
and references.
I think you would get a better answer if you reposted your question with the
words 'FlexGrid ActiveX' somewhere in the title, so someone with that type
of experience can answer.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
L

.Len B

Thanks for your time Jeanette.
It isn't so much the activeX control that I thought needed
updating as the data.

I guess you're saying that the latest detail record is in the
underlying recordset already so a requery isn't necessary.

I'll try a repaint, If that doesn't work, I'll force a redraw of
the ActiveX. I know how to do that ok from the main form. I wrote
the routine to draw it in the first place. It's just that the
parameters I pass are local to the main form, not to the subform
so I thought a requery would do the job more easily.
--
Len
______________________________________________________
remove nothing for valid email address.
| Sorry, I don't have any experience with any ActiveX controls - in fact
I
| stay well away from them as there can be problems with different
versions
| and references.
| I think you would get a better answer if you reposted your question
with the
| words 'FlexGrid ActiveX' somewhere in the title, so someone with that
type
| of experience can answer.
|
|
| Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
|
|
|
| | > Hi Jeanette,
| > I indeed do have Dirty=False earlier in the code followed by a
| > MsgBox saying "saved" then the RunCommand acCmdRecordGoToNew.
| >
| > In the bottom half of the main form I have a FlexGrid ActiveX
| > control which imitates an uneditable subform (datasheet) but
| > the height of each row varies depending on content. It is this
| > control that I want to update with the detail record just saved,
| > whilst leaving the true subform available and ready to enter a
| > brand new detail record. In fact the subform has no navigation
| > buttons so that the user cannot access earlier detail records
| > to edit (or even view) them.
| >
| > I haven't tested the DoCmd.GoToRecord variation yet to see if
| > it also errors with a 2046.
| >
| > --
| > Len
| > ______________________________________________________
| > remove nothing for valid email address.
message
| > | > | The way I see it, you would requery the parent form to pick up any
new
| > | information that has been added to the table/s the parent form is
based
| > on
| > | and then show them on the form.
| > | If you are adding and editing information in the subform, I am not
| > seeing
| > | why there is a need to requery the parent form. Perhfaps there is
more
| > to
| > | this than shown in your post.
| > |
| > | To go to a new record in the subform, I would use code like this on
the
| > save
| > | button
| > | --start of sample code
| > | If Me.Dirty Then
| > | Me.Dirty = False
| > | End If
| > |
| > | DoCmd.GoToRecord , ,acNewRec
| > | --end of sample code
| > |
| > |
| > | Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
| > |
| > | | > | >I have a form with a subform with no navigation buttons.
| > | > The subform has a cmdSave button to save the detail record.
| > | > In its click event I have
| > | > If Not Me.NewRecord Then RunCommand acCmdRecordGoToNew
| > | > Me.Parent.Requery
| > | >
| > | > Depending on the order of these two statements I get a
| > | > different problem.
| > | >
| > | > If I use the order shown, the RecordGoToNew works but it
| > | > is effectively undone by the requery. If I add another
| > | > RecordGoToNew line I get error 2046: The command or
| > | > action 'RecordGoToNew' isn't available now.
| > | >
| > | > If I switch order I receive the 2046 error.
| > | >
| > | > It seems that a requery prevents the GoToNew from working.
| > | >
| > | > So far I have avoided doing the requery at all but how do I
| > | > introduce it without creating a problem?
| > | >
| > | > --
| > | > Len
| > | > ______________________________________________________
| > | > remove nothing for valid email address.
| > | >
| > | >
| > |
| > |
| >
| >
| >
|
|
 

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