Solved

Open child form to new record and populate fields based on parent form

Posted on 2010-09-20
19
921 Views
Last Modified: 2013-11-28
Scenario:
frmSOP display information on SOPs that staff must be trained on
frmEvent is used to schedule training events for specific SOPs
User clicks "Schedule Event" button on frmSOP and frmEvent should open to a new record with the title of the Event prepopulated with the SOP name of the parent form.

The On_Click event for the frmSOP "Schedule Event" button is:
    DoCmd.OpenForm "frmEvent", acNormal, , , acFormAdd
The Form_Load event for the frmEvent is:
    Me.TrnId = Forms!frmSOP.TrnId

I get a message "You can't assign a value to this object"
0
Comment
Question by:NashVegas
  • 10
  • 4
  • 2
  • +2
19 Comments
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 250 total points
ID: 33719273

use this command line
 DoCmd.OpenForm "frmEvent", acNormal, , , acFormAdd, , OpenArgs:=Me.TrnId


in the load event of frmEvent

private sub form_load()
if len(me.openargs & "")>0 then
  if me.newrecord then
     me.trnid=me.openargs
 end if
end if

end sub
0
 
LVL 19

Expert Comment

by:MINDSUPERB
ID: 33719289
NashVegas,

Try to put the code in the On Current event of the form.

Sincerely,

Ed
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 33719299
btw, you mentioned, child form, is frmevent a subform of form frmSOP?
0
 
LVL 10

Expert Comment

by:t_hungate
ID: 33719444
Try putting a new field on your form txtTrngID and set its row source to =[Forms]![frmSOP].TrnId.

then use
DoCmd.OpenFrom "frmEvent", acNormal,,,acFormAdd

When you open the form you should see the correct TrnID in the new field.

Now try to set the value of your field.
Private Sub form_load()
Me.TrnId = Me.txtTrngID
End Sub

TLH
0
 

Author Comment

by:NashVegas
ID: 33719473
Capricorn,

frmEvent is not a subform. I used child form to mean it was called into existence from the frmSOP form. When I step through your code, Me.newrecord = 0 so it skips the openargs statement. Was this what you expected?
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 33719679
it  should be Me.newrecord = -1

check if the form frmEvent Allow additions property is set to YES
0
 

Author Comment

by:NashVegas
ID: 33719755
Capricorn and TLH,

I still get the "Can't assign values" error trying either of your suggestions.

Ed,

The "On Current" event doesn't execute when the form loads. I put breakpoints in the code and the breakpoints are never addressed if all I do is open the form with the "Schedule Event" button.

John
0
 

Author Comment

by:NashVegas
ID: 33719766
Cap,

Yes the allow additions property is set to Yes for frmEvents.
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 33720006
can you upload a copy of your db..

do a compact and repair first
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 33720389
You could create a new record in the child form's record source, populating the field from the value on the calling form, then open the child form to the last record.
0
 

Author Comment

by:NashVegas
ID: 33721621
Cap,

I have it uploaded. From the main menu, select SOP Profile and then click "Schedule Event" to open the Event Details form. Thanks for taking a look!
0
 
LVL 10

Assisted Solution

by:t_hungate
t_hungate earned 250 total points
ID: 33722019
Alright, I had to dig through here to see what all you had going on.  I think I narrowed it down to the recordset type for your event details form was a set to Snapshot, which will not allow edits.  I changed that, and still had some issues setting the value, so I use an on got focus event to do it.  

That took care of it.  All seems to be working now.

NOTES:
I also changed the record source to your tbl instead of the query you had, so you could include the trainers email address.  You should be able to change that back now.

I also noticed that you did not have anyone in your empl table assigned as trainers, the the combobox to select a trainer was not populated.  I just checked that box on a few people to make sure that worked as it should.

Hope this is what you were looking for.

TLH
0
 

Author Comment

by:NashVegas
ID: 33728983
TLH,

Thanks for your help! This got me closer in some ways, but in others it is creating more problems. It creates 2 records on the tblEvt table and neither record gets updated with the trainer or attendee list after the form is saved and closed. The second record gets created when the DoCmd.GoToRecord , , acNewRec code executes. This happens before the user has any opportunity to interact with the form.

Helen,

I made an attempt at interpreting your suggestion. I tried setting the child form's recordsource using an INSERT INTO statement, but I got an error message that this kind of SQL statement is not allowed to be used as a "row source". How do I create a new record in the child form's record source?

Thanks!
John
0
 

Author Comment

by:NashVegas
ID: 33729583
TLH,

Correction: I went back to your original code and noted that the 2nd of the pair of records that gets created every time the "Schedule Event" button is clicked does save the attendee, trainer, etc. If we can figure out how to prevent the first record from getting created we'll be laughing.

Cheers!
0
 

Author Comment

by:NashVegas
ID: 33735246
Okay, I've got it working now. I changed the tblEvts.TrnId field to display the traning name rather than the trnID value (although it is still bound to the trnID column). This simplified matters somewhat. I set the form's recordset type to dynaset and then added the "DoCmd.GoToRecord , , acNewRec" code to the child form's load event. This event also handles pre-populating the attendees based on training deficiencies. The form opens and is editable and all the data saves on the tblEvt table and only one record per event is created. If you open the Event Detail form on its own (rather than from the SOP Profile form) then the form shows all training events and is editable. All this is working as I intended.

I am not exactly sure what the silver bullet was that fixed my issue, but I am attaching the working prototype if anyone is interested. I'll split the points since several suggestions were helpful. Thanks!
0
 

Author Comment

by:NashVegas
ID: 33748511
This file replaces the file attached to comment 33721621

ViewTrainLite.accdb
0
 

Author Comment

by:NashVegas
ID: 33748629
This file replaces the file attached to comment 33722019
ViewTrain---TLH.accdb
0
 

Author Comment

by:NashVegas
ID: 33748646
This file replaces the file attached to comment 33735246
ViewTrainLite-2.accdb
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now