473,386 Members | 1,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Error when opening a form with selection from combobox

25
Hi,

I am trying to create a command button that:

1. Opens the form as selected from a combobox,
2. Creates a new record, and
3. Inserts the EmployeeID automatically.

Expand|Select|Wrap|Line Numbers
  1.    Dim stItem As String
  2.     Dim stDocName As String
  3.     Dim stLinkCriteria As String
  4.  
  5.     stItem = Forms!frmDigitalEquipment.CategoryList
  6.     stDocName = "frmDE" & stItem
  7.     stLinkCriteria = "[EmployeeID]=" & Forms!frmDigitalEquipment.EmployeeID
  8.  
  9.     DoCmd.OpenForm stDocName, , , stLinkCriteria, acFormAdd
But when I click on the button I get the error message: "Application-defined or object-defined error." After troubleshooting the code, I've narrowed problem down to line 5, but now I don't know how to fix it.

Your help would be much appreciated.

dstorms
Jun 5 '08 #1
7 1319
RuralGuy
375 Expert 256MB
If this code is on the frmDigitalEquipment form then you can reference the controls on the form by just using Me. ie: Me.CategoryList

Does this EmployeeID already exist in the RecordSource of the next form? Do you really have a bunch of forms named frmDE...? Why?
Jun 5 '08 #2
dstorms
25
This took care of 1 & 2:

Expand|Select|Wrap|Line Numbers
  1. 5.    stItem = Me!Combo9.Column(0)
Going to try fix step 3. The code opens the correct form in Add mode, but doesn't automatically fill in the EmpolyeeID field.
Jun 5 '08 #3
RuralGuy
375 Expert 256MB
Does this EmployeeID already exist in the RecordSource of the next form? Do you really have a bunch of forms named frmDE...? Why?
If not then you will need to pass the EmployeeID in the OpenArgs argument and catch it in the OnLoad event of the next form and put it in the control you want.
Jun 5 '08 #4
dstorms
25
If this code is on the frmDigitalEquipment form then you can reference the controls on the form by just using Me. ie: Me.CategoryList

Does this EmployeeID already exist in the RecordSource of the next form? Do you really have a bunch of forms named frmDE...? Why?
I figured out that the name of the combobox control was actually Combo9.

From what I understand, clicking on the button would open the from in add mode with all the data fields blank. I want to be able to copy the data from the EmployeeID field in the DIgitialEquipment form to the EmployeeID field in the newly opened form.

The frmDE prefix was used to keep these forms together in the database window, and I had several forms because I had separate tables for each type of digital equipment.
Jun 5 '08 #5
RuralGuy
375 Expert 256MB
Don't use a WhereCondition argument and here's a link on how to reference a control on another open form.
http://www.mvps.org/access/forms/frm0031.htm
Jun 5 '08 #6
dstorms
25
If not then you will need to pass the EmployeeID in the OpenArgs argument and catch it in the OnLoad event of the next form and put it in the control you want.
I got the first half right, but the OnLoad event may not be working the way I'd hoped. I've tried these two expressions:
=[Me].[frmDigitalEquipment]![EmployeeID]
=[EmployeeID]=[Me].[frmDigitalEquipment]![EmployeeID]
but neither would create the new record. I think it is because the EmployeeID control is a combo box that displys the name but stores a number for the value.
(Like a pulldown menu.) Would that have an effect on the script?
Jun 5 '08 #7
RuralGuy
375 Expert 256MB
Why would the EmployeeID control be a ComboBox in the 2nd form? You are not using Lookup Fields are you?
http://www.mvps.org/access/lookupfields.htm
Jun 5 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
7
by: Nicolae Fieraru | last post by:
Hi All, I am trying to change the rowsource of a combobox when I click on it. I played with many events, associated with the form and the combobox, but still haven't figured out what is the way...
4
by: Patrick Arkins | last post by:
I have a Main form (named FRM_Main in the Forms Window) with a Subform (named FRM_User_Search in the Forms window, form_User_Search on Forms_Main). FRM_User_Search has a combo-box (cboSort) the...
0
by: Susan Bricker | last post by:
The following error: "The current field must match the join key '?' in the table that seves as t the 'one' side of one-to-many relationship. Enter a record in the 'one' side table with the...
2
by: Susan Bricker | last post by:
I went back to read my post and found an error in my description ... here is the post, again, corrected: The following error: "The current field must match the join key '?' in the table that...
4
by: lesperancer | last post by:
I've got a comboBox with 2 choices and based on the choice, I make button A or button B visible if choose choice 1, button A is visible now, I undo the choice so that the comboBox is null, but...
8
by: g_man | last post by:
I am trying trap Runtime error 3022 (duplicates) in the click event of a command button that closes the form. I have code in the Form_Error event that does a good job of providing a more meaningful...
3
by: thorpk | last post by:
I posted this problem earlier in the month and some one decided it was better to change the subject and ask a completely different question. I am therefore reposting. I am hoping some one can...
1
by: billypit | last post by:
Hi, I am totaly new to MS Access. I have one form in MS Access in which i want that whenever i select an item from combobox then in the textbox on the same form or subform i want value from table...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.