Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Auto fill field on a 1st form when double-click a field on the 2nd form

Posted on 2014-04-29
5
Medium Priority
?
934 Views
Last Modified: 2014-05-04
I have a form open which contains a command button that opens a 2nd form which is a continuous form.  The first form stays open.  When the user double-clicks on a records first field I want a field on the 1st field to fill with a value on the 2nd form's record.

My code of the double-click event of the records first field is:

Forms!subfrmEstParts.cboType = Me.txtPaperType

I'm getting an error:

Runtime error: 2465
Application-defined or object defined error

--Steve
0
Comment
Question by:SteveL13
  • 2
  • 2
5 Comments
 
LVL 8

Expert Comment

by:Ganapathi
ID: 40029628
See if this helps. I created a blank worksheet with 2 sheets named Sheet1 and Sheet2 and placed a Button on Sheet1. Added the below code to the Sheet1. Works fine.

Private Sub Submit_Click()
ThisWorkbook.Sheets(2).Range("A2").Value = "Test"
End Sub

Open in new window

0
 

Author Comment

by:SteveL13
ID: 40029636
This is a MS Access topic/question.
0
 
LVL 40

Expert Comment

by:PatHartman
ID: 40029748
If I can trust your naming convention, you are referring to a subform.  That means your reference needs to change to include the main form.

Forms!frmMainForm!subfrmEstParts.Form!cboType = Me.txtPaperType

Forms!
   mainform name   !  subform name   .Form!   control name
0
 

Author Comment

by:SteveL13
ID: 40029968
I changed the code to read:

    Forms!frmEstimate!subfrmEstParts.Form!cboType = Me.txtPaperType

But now I get an error indicating it can't file the field subfrmEstParts (which isn't even a field, it's the subform name)  ?????

So I added the line of code to open the subform:

    DoCmd.OpenForm "subfrmEstParts", acNormal, , , acFormAdd, acWindowNormal

    Forms!frmEstimate!subfrmEstParts.Form!cboType = Me.txtPaperType

And still get the error indicating it can't file the field subfrmEstParts


????
0
 
LVL 40

Accepted Solution

by:
PatHartman earned 2000 total points
ID: 40030056
You can't open the subform directly.  ALSO - when you "push" something to a different form, that form MUST be open.  So the code won't work at all unless the form you are poking is actually open.  And the final warning is - you are poking the CURRENT record which may or may not be what you think it is.  This is a dangerous process plus, in a properly normalized schema you would not need to do this since a normalized schema does NOT contain duplicated data.

Check the Name property of the subform control.  It might be different from the name you are using.  When you reference the subform on the main form, you are actually referencing the control.  That's why the name you use is the Name property of the control.
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Suggested Courses

885 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