Solved

Create a new record with Combo Box

Posted on 2011-09-21
12
309 Views
Last Modified: 2012-05-12
Hi Guys,
I have two tables, Employees table and Stipend table. On my form I have a combo box to find the related data per employee.  What I would like to do is a button that when I click on it , it will clear the form and based on my combo box selection(employee name) to create a new stipend.
Both files are linked with the FileNo which is the id no of employee.  Thanks in advance.
0
Comment
Question by:Sheogorath
  • 7
  • 5
12 Comments
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 36576630
I will presum a standard set up where you are "referencing" the Employee ID in the combobox, but simply "displaying" the name.
Then try something like this

DoCmd.GoToRecord , , acNewRec
Me.txtEmpID = Me.cboEmployee
0
 

Author Comment

by:Sheogorath
ID: 36584665
Thank you but I am getting an error The Microsoft Office Access database engine cannot find a record in the table 'Employees' with key matching field(s) 'Stipend.FileNo'.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 36585128
Post a sample of your DB as it stands now.

Sample database notes:
1. Back up your database(s).
2. Combine the front and back ends into one database file.
3. Remove any startup options, unless they are relevant to the issue.
4. Remove any records unless they are relevant to the issue.
5. Delete any objects that do not relate directly to the issue.
6. Remove any references to any "linked" files (files outside of the database, Images, OLE Files, ...etc)
7. Remove any references to any third party Active-x Controls (unless they are relevant to the issue)
8. Remove, obfuscate, encrypt, or otherwise disguise, any sensitive data.
9. Compile the code. (From the VBA code window, click: Debug-->Compile)
10. Run the compact/Repair utility.
11. Remove any Passwords and/or security.
12. If a form is involved in the issue, set the Modal and Popup properties to: No
    (Again, unless these properties are associated with the issue)
13. Post the explicit steps to replicate the issue.
14. Test the database before posting.

In other words, ...post a database that we can easily open and immediately see and/or troubleshoot the issue.
And if applicable, also include a clear graphical representation of the *Exact* results you are expecting, based on the sample data.

0
 

Author Comment

by:Sheogorath
ID: 36588443
Thank you. Please see attached.
Sample-DB.accdb
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 36588588
Sorry, I can't seem to follow your design here...
Are you quite sure your tables are properly designed normalized and related?

What is the ultimate goal here again? (based on the DB you posted)
0
 

Author Comment

by:Sheogorath
ID: 36588624
Hehe Well,I am not sure!;) This is my first time working on access.  What I would like to do is based on the Employees ID create Stipends.
I would like to select the employee from the Combobox edit if necessary if not create a new stipend.
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 36588683
<Hehe Well,I am not sure!;) This is my first time working on access. >
...Then I suggest that you verify the design *First* before ever thinking about forms...

If the design is flawed, then the form will never work anyway...

In a *very general* sense, ...If one Employee can have many stipends, then this is a basic One to Many Relationship.
You have this already, but I am concerned about the primary key in the employees table (File Number)?
Is this unique to each employee?  If so, then why not call it EmpID, to avoid confusion...?
0
 

Author Comment

by:Sheogorath
ID: 36588754
Yes it is unique. I did change the FileNo to EmpID and I believe I changed it every where but still giving me this error. :S



SShot.jpg
0
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 500 total points
ID: 36590007
See this sample

Once the main and subforms are working correctly, Select the employee from the combobox, then simply click the "*" (New record button) on the subform to create a new stipend for the selected Employee.

Again, your main concern here should be with the table design, not the forms.

When/If the table design is updated, the forms may have to be redesigned anyway.

Again, this is all database basics...


JeffCoachman
Sample-DB-2-.mdb
0
 
LVL 74

Assisted Solution

by:Jeffrey Coachman
Jeffrey Coachman earned 500 total points
ID: 36592918
If you want this done by a button on the main form:

1. Drop a button on the main form
2. Insert code like this on the Click event:

Me.frmStipendSub.SetFocus
DoCmd.GoToRecord , , acNewRec
[frmStipendSub].Form![StipendAmount].SetFocus


;-)


Jeff
0
 

Author Comment

by:Sheogorath
ID: 36593403
Thanks for all the help.:) I created a new form from Employees table and created Stipends form and made the Stipends form Subform. Now it works as it is supposed to and I am able to add new records.Yayy!:)) Now I can ask some other questions hehhe
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 36594201
<Now I can ask some other questions >
Yes, about the design...

Your objective should be to describe the function/purpose of the database in general.
It is not clear if the other three tables are designed and linked properly.

JeffCoachman
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

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…
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

920 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

13 Experts available now in Live!

Get 1:1 Help Now