Solved

Create a new record with Combo Box

Posted on 2011-09-21
12
299 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

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…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Familiarize people with the process of utilizing SQL Server views 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 Microsoft Access…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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

12 Experts available now in Live!

Get 1:1 Help Now