Requery a form from its subform, then add new

  • Follow


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. 


0
Reply Len 2/18/2010 12:33:18 AM

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

".Len B" <gonehome@internode0.on0.net> wrote in message 
news:ud6A7HDsKHA.728@TK2MSFTNGP04.phx.gbl...
>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.
>
> 


0
Reply Jeanette 2/18/2010 8:04:24 AM


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.
"Jeanette Cunningham" <nnn@discussions.microsoft.com> wrote in message 
news:ua6cCEHsKHA.3800@TK2MSFTNGP06.phx.gbl...
| 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
|
| ".Len B" <gonehome@internode0.on0.net> wrote in message
| news:ud6A7HDsKHA.728@TK2MSFTNGP04.phx.gbl...
| >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.
| >
| >
|
|



0
Reply Len 2/18/2010 12:01:50 PM

".Len B" <gonehome@internode0.on0.net> wrote in message 
news:ef9ZsIJsKHA.5036@TK2MSFTNGP02.phx.gbl...
| 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.



0
Reply Len 2/18/2010 12:42:34 PM

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



".Len B" <gonehome@internode0.on0.net> wrote in message 
news:ef9ZsIJsKHA.5036@TK2MSFTNGP02.phx.gbl...
> 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.
> "Jeanette Cunningham" <nnn@discussions.microsoft.com> wrote in message
> news:ua6cCEHsKHA.3800@TK2MSFTNGP06.phx.gbl...
> | 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
> |
> | ".Len B" <gonehome@internode0.on0.net> wrote in message
> | news:ud6A7HDsKHA.728@TK2MSFTNGP04.phx.gbl...
> | >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.
> | >
> | >
> |
> |
>
>
> 


0
Reply Jeanette 2/18/2010 10:49:59 PM

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.
"Jeanette Cunningham" <nnn@discussions.microsoft.com> wrote in message 
news:OpV9nzOsKHA.5180@TK2MSFTNGP05.phx.gbl...
| 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
|
|
|
| ".Len B" <gonehome@internode0.on0.net> wrote in message
| news:ef9ZsIJsKHA.5036@TK2MSFTNGP02.phx.gbl...
| > 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.
| > "Jeanette Cunningham" <nnn@discussions.microsoft.com> wrote in 
message
| > news:ua6cCEHsKHA.3800@TK2MSFTNGP06.phx.gbl...
| > | 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
| > |
| > | ".Len B" <gonehome@internode0.on0.net> wrote in message
| > | news:ud6A7HDsKHA.728@TK2MSFTNGP04.phx.gbl...
| > | >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.
| > | >
| > | >
| > |
| > |
| >
| >
| >
|
|



0
Reply Len 2/18/2010 11:40:00 PM

5 Replies
448 Views

(page loaded in 0.161 seconds)

Similiar Articles:













8/1/2012 7:43:53 AM


Reply: