473,471 Members | 1,905 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Combo box adding new fields

Slaxer13
106 New Member
Hello ppl,

In one of my forms i have a combo box that whenever i create a new record it adds a new field everytime with the id of the value i put in the record before.

Example: i create a new record and the field on the combo is "water" (in the table the "water" id is "2")then when i start a new record the fields on the combo box this time will be "water" and "2".

Anybody have a clue why?

Any help appreciated.
Cheers, Slaxer13
Jun 30 '14 #1
39 1584
burrina
6 New Member
Is this combo bound and do you have code using the afterupdateevent?
Jun 30 '14 #2
Slaxer13
106 New Member
Yes it is bound to a table. As for the AfterUpdate Code is the following:
Expand|Select|Wrap|Line Numbers
  1.  Me.cboTipo.RowSource = "SELECT Cod_Tipo_Atendimento, TipoAtendimento " & _
  2.                            "FROM tblTipoAtendimento " & _
  3.                            "WHERE Cod_Area_Atendimento = " & Nz(Me.cboArea)
  4.     txtAbreviatura.Value = cboArea.Column(1)
Basically the code is supposed to set the values of another combo box according to the value on this one. and when the value on this combo box is choosen i have a textbox "txtAbreviatura" that will receive the abreviation of the value i choose
Jun 30 '14 #3
Seth Schrock
2,965 Recognized Expert Specialist
Another place to look would be in the form's OnCurrent event to see if you are setting the value using code.
Jun 30 '14 #4
Slaxer13
106 New Member
Form's onCurrent Code:
Expand|Select|Wrap|Line Numbers
  1. Dim rst As DAO.Recordset
  2.     Dim lngCount As Long
  3.     Set rst = Me.RecordsetClone
  4.     With rst
  5.     .MoveLast
  6.     lngCount = .RecordCount
  7.     End With
  8.     Me.txtCount2 = "Registo " & Me.CurrentRecord & " de " & lngCount
It has nothing that would mess with the cbo
Jun 30 '14 #5
Slaxer13
106 New Member
Sorry for troubling you people. The problem is sovled. My form was updating three tables and two of them where updating twice because my combo boxes where supposed to be unbound and they weren't. The moment i unbounded them the problem went away. Anyway thanks for the help ;)
Cheers, Slaxer13
Jul 1 '14 #6
twinnyfo
3,653 Recognized Expert Moderator Specialist
slaxer,

My comment may be off topic, but I think relevant to the posts you have been making, in general.

It seems you have recurring problems with combo boxes and how they interact with your forms and tables. Some recurring themes that I see are:
  1. Combo boxes with constantly changing row sources
  2. Combo boxes that set the values of other text boxes and/or
  3. Text boxes that are utterly dependent upon the ID of a combo box
It appears, to my cursory glance at your implementation of combo boxes/text boxes relying on those combo boxes, that you are highly over-complicating things.

It "appears" that you have a form. The form is bound to a table. There is a combo box, which is not bound. You also have a text box which may or may not be bound. Then when you go to a record, the user updates the unbound combo box. Then the combo box updates the text box with the ID of the combo box (which is the value of the combo box in the first place). Then the text box, which now has the ID of the combo box updates the value int he table (whether by being bound or unbound).

Do you see where I am going? Why can't you simply have a combo box, bound to the field on the table, so that when a user updates the combo box, the value in the table is updated?

I just want you to be aware of the apparent over complication your forms appear to be creating. If I am missing something, please explain.
Jul 2 '14 #7
Slaxer13
106 New Member
No, you are right. My knowledge is the basic at access and seems i am really complicating things. Sorry to ask this but can you tell me how to do what you have said? The part where "when a user updates the combo box, the value in the table is updated" is it through vba?
Jul 2 '14 #8
twinnyfo
3,653 Recognized Expert Moderator Specialist
slaxer,

typically, if you have a table with a field that uses a foreign key, with a lookup field, when you add that field to your form, it will be a bound combo box. When you open the form, whenever you update the combo box, you have updated the field in the table. No VBA required. It is the basic setup for lookup fields.

An example:

I have a table tblOrders. That table has several fields OrderID, OrderDate, Vendor, OrderTotal.

For the field Vendor, we could have it as a text value (i.e. "Smith's Foods", "Jones Shipping" etc.). But, whenever we have orders from the same Vendor, we are duplicating the data in the table. Plus, we have the possibility for mis-typing the name (i.e. "Smyth's Foods"). Then, when we run a query to find out our biggest vendors, we would have two vendors for Smith's Foods, one of which is correct, one which is incorrect, but neither would be accurate.

So, we create a table for vendors, in which we have VendorID, VendorName, Vendor Address, etc. Then in our tblOrders, instead of using the Vendor name, we use the index (VendorID)--this is the foreign key--by using a lookup field. This saves a ton of data (especially when you have lots of records).

You may already understand this principle, so forgive me if I am repeating what you already know, but it appears that your forms are not operating on this principle, but you are trying to re-invent the wheel by using unbound controls to update your table. Remember, the only way you can use an unbound control to update a table is through VBA (there are some clumsy ways to do it, but VBA works easiest). However, in your situation, it appears that properly created bound controls are what you need.

Let me know if this helps you out.
Jul 2 '14 #9
Slaxer13
106 New Member
At the moment i have no FK (foreign Keys) in any table. But i kinda understand what you mean in your exemple. It seems i may have to change somethings in order for this to work. I will try to do things the way you said in the example.

And you don't need to ask forgiveness because the more times i ear things the most likely is that i am going to understand them better and use them more eficiently ;)
Jul 2 '14 #10
twinnyfo
3,653 Recognized Expert Moderator Specialist
Keep in mind that your problem here may be related to the problems you are having in your other current thread. Perhaps we have been seeking solutions based on principles that are not in place in your database forms and tables.

This could be why the threads are lengthy and apparently come to no conclusions. However, we will continue to crack away at this issue until we make you a pro!!
Jul 2 '14 #11
Slaxer13
106 New Member
I think it is related. And i noticed something. In the afterupdate of the cboarea if i don't use that select statement to define the values of the other cbo my values of previous records remain untouched
Jul 2 '14 #12
Slaxer13
106 New Member
I tried putting that statement in comment and i works great
Jul 2 '14 #13
twinnyfo
3,653 Recognized Expert Moderator Specialist
Your form is still "behaving" like it is in continuous forms mode.....
Jul 2 '14 #14
Slaxer13
106 New Member
How do i change it to single view?
Jul 2 '14 #15
twinnyfo
3,653 Recognized Expert Moderator Specialist
In the form's design view, in the Property Sheet, look for "Default View". Set as Single Form. Then, just to make sure, set Allow Form View should be set to Yes. The other four views (Datasheet, PivotTable, PivotChart and Layout may be set to No, but do not need to be.
Jul 2 '14 #16
Slaxer13
106 New Member
Good day to all.
I changed it twinnyfo, it was in continuous form view. Thanks.
Still the problem remains and its because of the cboafterupdate event...
Jul 3 '14 #17
twinnyfo
3,653 Recognized Expert Moderator Specialist
Important question here..... Does it still update ALL PREVIOUS records to null, like previously? If it does, there must be something beyond the continuous forms issue.

If it just translates to null, that is now our focus.....
Jul 3 '14 #18
Slaxer13
106 New Member
Yes it does. It updates all previous records to null except thos with the same value.

Example: If in the cbotipo of the new record the value is "car" then it updates all previous records to null that don't have the cbotipo value as "car". As for the ones that have "car" as a value they remain untouched.

PS: Sorry for late reply. Was in reunion with teacher and tutor
Jul 3 '14 #19
twinnyfo
3,653 Recognized Expert Moderator Specialist
And the AfterUpdate Event of the Combo Box you listed in Post #3, this is the only code that fires?

I am suspecting that your Form is showing something different than what is in your table (or at least what ought to be in your table.

What are the values that "ought" to be in your table. If there are indexes used for lookup fields, please use the indexes. When you select something in cboArea, what are the values that should be populated in cboTipo?

In your Table, can the field for Area be any value? I.e., what is the row source (from the Table, not the Form)? Likewise, in the Table, what is the row source for your Field for Type?

My thought is that when you limit the rowsource in cboTipo, when you move to a record that does not contain one of those values in cboTipo, it reverts to Null (or at least it appears as Null on the Form). have you checked to see if the values in the Table have actually changed when you just change one record? Or, are you flipping through the records on your Form and getting these results?

Believe it or not, I think we are actually making progress, but it has taken us a while to ask the right questions to move in the right direction.....
Jul 3 '14 #20
Slaxer13
106 New Member
In the table the records are there but when i look through the records in the form they are null except the ones with the same value as the last one created. As for the field type is text.
Jul 3 '14 #21
Slaxer13
106 New Member
For the rest of today (my last internship day) all that i will do won't count for anything but i'm curious to solve this before letting go of this database.
Jul 3 '14 #22
twinnyfo
3,653 Recognized Expert Moderator Specialist
Your Post #21 just gave me great insight! The reason those values are Null on the form, but not in the Table is because the Combo Box does not have a corresponding value for the field.

One way to fix this is to add some code to the OnCurrent Event of the Form. Requery the row source of cboTipo just like you show in Post #3 (be sure to requery the combo Box).

Then all records should show their appropriate value (I hope!).

Let me know how it goes--hope you stick around the forum even after the internship!
Jul 3 '14 #23
Slaxer13
106 New Member
Expand|Select|Wrap|Line Numbers
  1. Me.cboTipo.RowSource = "SELECT Cod_Tipo_Atendimento, TipoAtendimento " & _                           
  2. "FROM tblTipoAtendimento " & _                            
  3. "WHERE Cod_Area_Atendimento = " & Nz(Me.cboArea)
  4. Me.cboTipo.Requery
  5. txtAbreviatura.Value = cboArea.Column(1)
  6.  
Like this?
Jul 3 '14 #24
twinnyfo
3,653 Recognized Expert Moderator Specialist
Yep, although, as discussed, the Abreviatura value is superfluous.

You may also have to add:

Expand|Select|Wrap|Line Numbers
  1. Me.Refresh
right after

Expand|Select|Wrap|Line Numbers
  1. Me.cboTipo.Requery
Let me know if it works...
Jul 3 '14 #25
Slaxer13
106 New Member
works but raises another problem... now,because this is trigered in the oncurrent event my cbotipo doesn't show any values when i am creating or editing. And not that it matters but when i choose cboarea it doesn't fill the txtabreviatura.
Jul 3 '14 #26
twinnyfo
3,653 Recognized Expert Moderator Specialist
It should still be in the cboArea AfterUpdate Event. It is required in both places.

The "Best" practice would be to have those operations in a separate function that is called from both locations, but for now, for these purposes it should work fine in both locations.
Jul 3 '14 #27
Slaxer13
106 New Member
I can do the function that's easy. I'll try and say how it goes
Jul 3 '14 #28
Slaxer13
106 New Member
Now it stopped working again. When this code is in the afterupdate event it stops working :/
Jul 3 '14 #29
Slaxer13
106 New Member
I did this:
Expand|Select|Wrap|Line Numbers
  1. Public Function cboUpdate()
  2.  
  3.     Me.cboTipo.RowSource = "SELECT Cod_Tipo_Atendimento, TipoAtendimento " & _
  4.                            "FROM tblTipoAtendimento " & _
  5.                            "WHERE Cod_Area_Atendimento = " & Nz(Me.cboArea)
  6.     Me.cboTipo.Requery
  7.     Me.Refresh
  8.     txtAbreviatura.Value = cboArea.Column(2)
  9.  
  10. End Function
And called it in cboArea_AfterUpdate and in Form_OnCurrent
Jul 3 '14 #30
twinnyfo
3,653 Recognized Expert Moderator Specialist
What were the results of your changes?
Jul 3 '14 #31
Slaxer13
106 New Member
None. It's the same as before. When i removed the code (put as comment) it worked fine but didn't limit the values of cbotipo. Is there another way to limit the cbotipo values according to the cboarea?
Jul 3 '14 #32
twinnyfo
3,653 Recognized Expert Moderator Specialist
So, the code that was previously working in the AfterUpdate event is now not working?

In line 8 above, just to make it clear for the code, change to Me.txtAbreviatura = Me.cboArea.

BTW, no need for the .Value, as this is the default property....
Jul 3 '14 #33
Slaxer13
106 New Member
Ok. No no. The program works if i don't have those code lines:
Expand|Select|Wrap|Line Numbers
  1.  Me.cboTipo.RowSource = "SELECT Cod_Tipo_Atendimento, TipoAtendimento " & _
  2.                             "FROM tblTipoAtendimento " & _
  3.                             "WHERE Cod_Area_Atendimento = " & Nz(Me.cboArea)
  4.      Me.cboTipo.Requery
  5.      Me.Refresh
  6.  
when i put them as commentary the program works but doesn't filter cbotipo values. if i remove them from commentary the program doesn't work but cbotipo has its values filtered
Jul 3 '14 #34
twinnyfo
3,653 Recognized Expert Moderator Specialist
Is this on every record that it does not work or only on new records?
Jul 3 '14 #35
Slaxer13
106 New Member
When i call the function in a new record it works but after i save the records in cbotipo of previous records that aren't of equal value become null. if i don't cal the function, cbotipo hasn't got the values restricted but the previous record don't become null when i save
Jul 3 '14 #36
Rabbit
12,516 Recognized Expert Moderator MVP
If you don't specify a return value, Nz will return a blank string if the value is null. So your SELECT statement becomes
Expand|Select|Wrap|Line Numbers
  1. SELECT fields
  2. FROM table
  3. WHERE field =
Which is incorrect because you have nothing after the =.
Jul 3 '14 #37
Slaxer13
106 New Member
Sorry for the late reply. No internet at home and internship is over. So because i don't have anything after the (=) they are returning null. I'll try it at home and get back as soon as i can.
Thanks. Cheers, Slaxer13
Jul 7 '14 #38
twinnyfo
3,653 Recognized Expert Moderator Specialist
Yes, instead of Nz(Me.cboArea), make it Nz(Me.cboArea, 0). This will at least cause the query to run, even if cboArea is Null (a new record).
Jul 7 '14 #39
Slaxer13
106 New Member
Thanks. I haven't had time to try it but i hadn't forgot about it. When i have time i'll try and post the result here ;)

Cheers, Slaxer13
Jul 8 '14 #40

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

Similar topics

19
by: tweak | last post by:
I have been messing around with buffers, and I found it peculiar that the code below will run without a segmentation fault. As far as I know, overwriting the allocated space from a call to...
3
by: hmiller | last post by:
Hey everyone, I am having a hell of a time trying to set this menu system up. Here's what I'm trying to do. Combo Box One; is populated by names under properties "row source" "Phase 1"...
11
by: Steven Jones | last post by:
I have a C program that prints out two lines as follows: Line 1 Line 2 What I would like is for this program to sleep for one second, and then print out two more lines, overwriting the...
6
by: Dave | last post by:
I want to put the information that the user selects in my combo boxes into a subform that lies on the same form as the combo boxes. Thanks for your help already, Dave
6
by: dougmeece | last post by:
Hello, I have a form that I would like to auto-populate text boxes in based on the selection made from a combo box. I have set the form record source to a table "SubmittedTo" which contains 3...
27
by: Jason | last post by:
Hi, I need to open an existing file, seek to a position at X number of bytes, and write out Y number of bytes overwriting any existing bytes, but no erasing any other data. Is this possible? ...
3
by: barneymonkeyman | last post by:
Firstly, I'm new to Access and VB code and what i do know is completely self taught from helpand websites like this, so be gentle. I want to have a subform displayed depending on a selection...
0
by: Gordon Padwick | last post by:
A form contains controls, one or more of which can be other forms. A form that contains another form is known as a main form. A form contained by a main form is known as a subform. A subform itself...
1
by: Yousaf Shah | last post by:
Hello everybody Thanks to Mr Lysander who guided me in building my data base. I have tried to synchronize two combo boxes named “Province” and “City” by method provided in Access Help so that I...
0
by: skavinkar | last post by:
While installing application i want to prevent overwriting my DB file if it already exists at specified location. As i am new to using Installshield could any please guide. Tried setting Never...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.