Solved

Create a new record with Combo Box

Posted on 2011-09-21
12
319 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

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
 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Archiving Access table older than 6 months 9 39
Access datasheet - showing a number in scientific notation 4 23
aggregate query? 20 53
Switch 5 18
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

831 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