Re: Accessing data from a subform in the parent form's recordset



DoCmd.OpenForm "frm_ModifyFirearms", acNormal, , , acFormAdd, acDialog

I had asked why you opening this form in dialog mode? Is there a particular
reason for this? (if there is not, you much better off to open the form as
model, and NOT dialog. If you use dialog, then you can't even use the menu
to go edit->undo, and you see later on, you can't use the calling code to
set the foreign key value.

So, we should resolve the above issue, and change this form to model, and
NOT use dialog. About the only reason why you would use dialog is if you
have calling code that needs to wait until the form is done (but, as
mentioned, you can' even use the ms-access menus with a dialog form, so,
they
really do tie your hands. Also, it is significantly important if you *do* in
fact need a dialog form, as that can significantly change the suggestions
and
approaches I offer to you. So, we should figure out why this form needs to
be dialog (it is not normal in this case for the form to be dialog).

The next thing to deal with is you are opening the frm_ModifyFirearems in
addmode, but then you suggest you jumping into a sub-form (under a tab) on
this form. KEEP IN MIND if you do not edit any field in this newly opened
form, you cannot enter into child forms to add related data. You **must**
dirty the parent record BEFORE you attempt to enter into a child form.

Once again, if
what I just stated is NOT clear, ask for further clarification . The reason
for
this question is if the user is not actually editing the underlying record
for Modifyfirearems, then *ms-access* will NOT have yet set the PK value
for Modifyfirearems, and that further means ms-access will be un-able to
add and set the foreign key value for dbtImages table.

In other words, opening form
ModifyFirearems in add mode will NOT add the record ***unless*** the user
edits some data on frmModifyFirearems BEFORE they attempt to edit data in
dbtImages (subform).

If the above is in fact your case, then you going to have to use code to
***dirty*** the frm_ModifyFirearems record BEFORE you move into to the
sub-form with image table.

And, if the above is the case, the best approach is do dirty the record
*after* the openform command, and that means you can't use acdialog (so, all
these issues are interrelated).

I would suggest the following:

dim strF as string
strF = "frm_ModifyFireArms"
DoCmd.OpenForm strF, acNormal, , , acFormAdd
forms(strF)!weaponid = me!firearm_id

Now, when you go into the tab subform in frm_ModifyFireArms, there will be a
pk id available for the image sub-form.

***NOTE*** as mentioned, if the user needs to, or will be editing values in
frm_ModifyFireArms *before* they go into the sub-form with images , then
you can eliminate the code of:
forms(strF)!weaponid = me!firearm_id,

since editing data *in* the form
will dirty the record, and trigger creation of a PK value for
frm_ModifyFireArms.

So far, we only adding ONE line of code to your original question *if* we do
this right...

Also, the above design assumes you only adding ONE record to
frm_ModifyFireArms (that means you should set his forms allow additions =
no, because the openform command in adFormAdd will override this setting for
ONE record, and the user will have to close the form to add additional
records (and, forcing the close is done by using model forms, NOT USING
acDialog forms).

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pleaseNOOSpamKallal@xxxxxxx




.



Relevant Pages

  • Re: Accessing data from a subform in the parent forms recordset
    ... There is no particular reason I ... KEEP IN MIND if you do not edit any field in this newly opened ... sub-form with image table. ... And, if the above is the case, the best approach is do dirty the record ...
    (microsoft.public.access.formscoding)
  • Re: appending .doc to save files
    ... The main reason I suggest that people should never open any file from their ... But what Harry says is also important: You may not be editing the original ... >> My faulty memory is dragging up some information that John McGhie once ... Always save them to your desktop, edit, save, and then ...
    (microsoft.public.mac.office.word)
  • Re: Data still disappearing
    ... When I click the Edit icon, it displays the information data about the file. ... > Can you try opening for edit? ... >>> the first document in the view. ...
    (microsoft.public.sharepoint.windowsservices)
  • Re: Data still disappearing
    ... any change you make by hand to the contents of the WSS database means that ... > When I click the Edit icon, it displays the information data about the ... > each document in the library and "Edit" the info (just click on the Edit ... >>>I am opening the document. ...
    (microsoft.public.sharepoint.windowsservices)
  • Re: Mouse function lost within Word 2003 document
    ... dirty workarounds but in this case there really isn't a reason to keep ... troubleshooting mode which prevents Normal.dot, add-in, and personal ... Your Winword is chewed. ... but I found a dirty work around that I am using ... ...
    (microsoft.public.word.application.errors)