473,385 Members | 1,736 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,385 software developers and data experts.

Use a form to update a table

158 100+
I've got a simple form with one dropdown box and 2 text boxes. the drop down box chooses a sales territory and then one of the other text boxes automatically shows whose in the sales territory shown. All the info is being pulled from one table. I'm having a lot of trouble figuring out how to take user input out of the second text box (which would be the new sales rep) and replace the old sales rep in the table. Any help would be greatly appreciated!
Mar 17 '08 #1
13 2220
Scott Price
1,384 Expert 1GB
Unless there's more to your problem than you mention, there is no need to use two text boxes to accomplish this! Just make sure that the control source of the text box is set to the field in the table that contains your old sales rep. Then whatever changes the user types in are automatically stored in that field.

However, if you wish to reduce possible user entry errors, a second combo box that shows available sales reps should be used so that the user can simply select the rep from the combo box instead of having to type the name in.

Regards,
Scott
Mar 17 '08 #2
Jollywg
158 100+
Scott,

Thanks for the response, but when i set the dropdown box's Control Source to something it does not let me choose a sales territory from the list, so i have it blank and the Row Source to [tblTerritory]. I have the one text box control source set to the salespersons name, but when i go to type in anything the status bar says "Control can't be edited; it's bound to the expression '[tblTerritory]![Sales_Name]". I get where your going with this, but i dont know how to relate the territory number to the corresponding sales name so i know that i'm changing the correct salesperson, instead of the first person in the table.
Mar 17 '08 #3
Scott Price
1,384 Expert 1GB
The accepted way of doing this is to have an 'unbound' combo box like you have. It's control source set to nothing, the row source set to something like this:
Expand|Select|Wrap|Line Numbers
  1. SELECT SalesRegionID, SalesRegion FROM tblSalesRegions
This means you now have two columns in your combo box. Set the bound column to column number 1 (the ID column). Then set the Column Widths to 0", 1.5" (or wider if needed). Now when you select a sales region from the combo box, it returns a number corresponding to the ID value of that region.

Make a query in design view that combines the SalesRegions table with the SalesPersonnel table (if you don't have the equivalent of these two tables, you need to restructure your database. See Normalisation and Table structures). Now you set as a WHERE criteria for the SalesRegionID in your query a reference to the combo box result. I.E.
Expand|Select|Wrap|Line Numbers
  1. WHERE tblSalesRegions.SalesRegionID = Forms![FormName]![ComboBoxName]
.

Now you go back to the form in design view, double click the small square in the upper left corner to bring up the Properties dialog box, and set the Record Source for the form to the query you created. Go to your text box and set the Control Source for your text box to the field corresponding to the Sales Person Name. You'll need another text box (Set it's Visible attribute to False) with Control Source set to the ID field for the SalesRegion. Now whatever changes you make in the text box are written through the query into the table.

Setting the other combo box up will be similar. Set it's Control Source to nothing (leave blank in other words). It's Record Source will be something like:
Expand|Select|Wrap|Line Numbers
  1. SELECT SalesPersonName FROM tblSalesPersonnel
. It has only one column, so will be a bit different from the first combo box. Now you will write the simple code to make the selection in this combo box reflect in the text box. In the Properties dialog box for the second combo, click the ellipsis (...) to the right of the After Update event on the Events tab. Choose Code Builder. This will put you into the VBA Editor window. Between the lines that say Private Sub [ComboBoxName]_AfterUpdate() and End Sub write code like this:
Expand|Select|Wrap|Line Numbers
  1. Me.[TextBoxName] = Me.[ComboBoxName]
  2. Me.Dirty = False
If this is too simplified, I apologize...

Kind Regards,
Scott
Mar 17 '08 #4
Jollywg
158 100+
Scott,
That is almost exactly what i needed. The only problem i am having is with the two text boxes. I have the invisible text box's control source set to SalesRegion and the visible text box set to Salesperson and the form's RecordSource is set to "tblTerritory" (which holds the salesRegion and salesperson name). Whenever i go to test it, the combo boxes work together, but the textboxes are not updated. I even resorted to just typing in a sales region and a salesperson, but then it gives me an error "The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship." We're almost there.

Thank you so much

Matt
Mar 19 '08 #5
Scott Price
1,384 Expert 1GB
What is the current structure that you have? By structure I mean the table names, fields, primary keys, form names, combo box names, text box names, control sources, etc.

Regards,
Scott
Mar 20 '08 #6
Hi I'm having a similiar issue though probably much simpler as I am newbie to access. I have a form which updates my table just fine except for some fields in the form are expressions, and the results of the expressions do not populate the table, but the form always remembers the results of the expression. also if I open the "datasheet" view it looks like the table but with the results of the expressions present in the appropriate fields.
Mar 20 '08 #7
Scott Price
1,384 Expert 1GB
Matus1976,

You have asked your question in another member's thread. This is called thread hijacking and is not allowed on this site. There are various reasons for this, the principal of which is that it typically diverts the flow of the thread away from his needs and into yours. Another is that it will tend to mean that your new question is not seen as such, and may get overlooked by many of our experts (You appreciate that they're not looking for answered questions).
Please post your questions in their own threads in future (See How to Ask a Question).

MODERATOR
Mar 20 '08 #8
Matus1976,

You have asked your question in another member's thread. This is called thread hijacking and is not allowed on this site. There are various reasons for this, the principal of which is that it typically diverts the flow of the thread away from his needs and into yours.

MODERATOR
My apologies I was not trying to hijack the thread, I started a new thread with my question. Can these posts be deleted?

Thanks

We'll leave it as is. No worries, and thanks for starting your own thread.

Welcome to the Scripts!

Regards,
Scott
Mar 20 '08 #9
Jollywg
158 100+
I have 3 tables tblZipCode, tblManager, tblTerritory

The table i've been trying to update is tblTerritory

It's made up of:

tblTerritory(Territory_Number; Salesperson; Manager_Name; District_Name;)

tblZipCode(ZipCode; Territory_Number; Num_Sales_Outlets;)

tblMangaer(District_Name; Manager_Name)

On the form I have 2 text boxes and 2 comboboxes.

cboCurrentTerritory is the combobox that has two columns in it.
cboCurrentSalesperson is the combobox that reflects the salespersons name from the territory.

*the comboxs work correctly*

txtNewSalesperson I have cleared out the attributes
txtTerritory is the hidden textbox, but other than that i have cleared out the attributes

Matt
Mar 21 '08 #10
Scott Price
1,384 Expert 1GB
It looks like you just need to bind your txtNewSalesperson to the SalesPerson field in the table. By 'bind' I mean set it's control source to that field.

Regards,
Scott
Mar 22 '08 #11
Jollywg
158 100+
I'll give that a try, but the last time i did that it said that i could not change the contents because the control source was set to ".....".
Mar 24 '08 #12
Jollywg
158 100+
Scott,
Thanks for all your help, I finally got it.

Matt
Mar 24 '08 #13
Scott Price
1,384 Expert 1GB
Glad you got it working! I just got back to computer access from a few days on the road.

Regards,
Scott
Mar 26 '08 #14

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

Similar topics

4
by: Eric | last post by:
Hey Everyone.. I have a form that has approximately 7 text fields and 1 checkbox. Generally when this form is submitted(to itself BTW) it works fine, however, when the checkbox is only field...
2
by: Lyn | last post by:
Hi, I am working on a genealogy project in which I have two tables: Person -- one record for each person in the family. Each record has a unique Autonum field (IDPerson). Partnerships -- one...
14
by: Abhi | last post by:
FYI: This message is for the benefit of MS Access Community. I found that this prblem has been encounterd by many but there is hardly any place where a complete solution is posted. So I thought...
1
by: MissiMaths | last post by:
I am creating a reference table of all the information used to draw a sample. I start by first clearing the table in form1 using a delete query. Then after the user selects certain options, i...
4
by: Rich_C | last post by:
I'm sure this is very simple, but I have very little experience with javascript -- and what I do know isn't helping me here. I have a simple form where users can enter a quantity (qty) and cost...
3
by: eholz1 | last post by:
Hello PHP programmers. I had a brilliant idea on one of my pages that selects some data from my mysql database. I first set the page up to display some info and an image, just one item, with a...
10
by: sara | last post by:
Hi - I have been struggling with solution ideas for this now for almost 2 weeks, and have not been able to figure this out. I have a user who creates a Purchase Order (tblPOData). In some...
4
by: prosad | last post by:
hello, Just solved a problem using Javascript onclick, can click on any cell in a dynamic table and it will pass the innerText object value to my form text field. parts of code given below: ...
2
by: ssmith147 | last post by:
Hi, I'm somewhat familiar with access and vb programming (I can read someone else's code, for the most part), but I'm still very green when it comes to creating solutions for my own needs. I'm...
1
by: chromis | last post by:
Hi, I'm having trouble fully implementing the edit section of a contact admin system, so far I have written the following: - Bean (Contact.cfc) - Data Access object (ContactDAO.cfc) - Gateway...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.