Solved

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

Posted on 2014-04-29
5
852 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
Comment Utility
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
Comment Utility
This is a MS Access topic/question.
0
 
LVL 34

Expert Comment

by:PatHartman
Comment Utility
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
Comment Utility
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 34

Accepted Solution

by:
PatHartman earned 500 total points
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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.

763 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

5 Experts available now in Live!

Get 1:1 Help Now