473,385 Members | 1,732 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.

Combobox: Delete the data selected and it re-appears???

I have a combobox with the RowSourceType set to Table/Query and the
RowSource is an SQL query that references a separate lookup table that
contains the data that can be selected in the combobox. Also,
limittolist & autoexpand are set to Yes. Control source is set to the
main table field where the data will go.

I can highlight the data that was previously selected in the combobox,
and press the delete key to remove it, but after I move the mouse and
click on another field, the data that was just deleted re-appears in
the combobox? I have three comboboxes and they are all doing this.
Also, if I keep trying to delete, eventually it accepts it? I checked
everything, and I do not have anything coded that should be causing
this. Also, I noticed a few other posts with this problem, but found
no solution.

Each lookup table has referential integrity with cascading updates set
as 1 to many, and is tied to the main table (many). I’m not sure if
this is part of the problem?
Jul 23 '08 #1
9 5499
To reliably delete an item from a combobox that is based on table data -
you need to capture the event of the combobox when you press the delete
key (maybe the keyup event of the combobox). In this event have your
vba code check if the delete key was pressed. Here is a sample - I use
the combobox KeyDown event (and for me the keycode is 46 when I press
the delete key while the combobox has the focus

Private Sub Combo7_KeyDown(KeyCode As Integer, Shift As Integer)
Debug.Print "keydown " & KeyCode & " " & Combo7.Text
If KeyCode = 46 Then
Dim arr() As String, str1 As String, i As Integer
arr = Split(Combo7.RowSource, ";")
For i = 0 To UBound(arr)
If str1 <"" And Right(str1, 1) <";" Then str1 = str1 & ";"
If arr(i) <Combo7.Text Then str1 = str1 & arr(i)
Next
Combo7.RowSource = str1
End If

End Sub

I use a value list for the rowsource of my combobox. I then strip off
the deleted value if it is part of the current rowsource and then reset
the new rowsource to the combobox. If you are using a table for a
rowsource - then you need to delete the value from the table as follows:

DoCmd.RunSql "Delete * From rowSourceTable Where comboValue = '" &
combo7.Text & "'"

Note: if the value is a text value (not a numeric value) then you need
to delimit the parameter with single quotes.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Jul 23 '08 #2
On Wed, 23 Jul 2008 11:38:03 -0700 (PDT), "Greg (co*****@gmail.com)"
<co*****@gmail.comwrote:

What Rich said, but perhaps he misunderstood and all you want to do
is:
A form has a dropdown with initially no selection made.
I select a value
After I tab away from that control, I want to undo the selection
(going back to <blank>).

Can you confirm?

-Tom.
Microsoft Access MVP
>I have a combobox with the RowSourceType set to Table/Query and the
RowSource is an SQL query that references a separate lookup table that
contains the data that can be selected in the combobox. Also,
limittolist & autoexpand are set to Yes. Control source is set to the
main table field where the data will go.

I can highlight the data that was previously selected in the combobox,
and press the delete key to remove it, but after I move the mouse and
click on another field, the data that was just deleted re-appears in
the combobox? I have three comboboxes and they are all doing this.
Also, if I keep trying to delete, eventually it accepts it? I checked
everything, and I do not have anything coded that should be causing
this. Also, I noticed a few other posts with this problem, but found
no solution.

Each lookup table has referential integrity with cascading updates set
as 1 to many, and is tied to the main table (many). I’m not sure if
this is part of the problem?
Jul 24 '08 #3
Yes Tom you are correct. If I make a selection in the dropdown, but
latter decide to remove what was selected,
I would highlight it with the mouse and hit the delete key. The
problem is, as soon as I click on another field the
deleted data reappears in the field. However, this does not happen if
I tab or CR out.

Thanks
Greg
On Jul 24, 12:17*am, Tom van Stiphout <no.spam.tom7...@cox.netwrote:
On Wed, 23 Jul 2008 11:38:03 -0700 (PDT), "Greg (code...@gmail.com)"

<code...@gmail.comwrote:

What Rich said, but perhaps he misunderstood and all you want to do
is:
A form has a dropdown with initially no selection made.
I select a value
After I tab away from that control, I want to undo the selection
(going back to <blank>).

Can you confirm?

-Tom.
Microsoft Access MVP
I have a combobox with the RowSourceType set to Table/Query and the
RowSource is an SQL query that references a separate lookup table that
contains the data that can be selected in the combobox. Also,
limittolist & autoexpand are set to Yes. Control source is set to the
main table field where the data will go.
I can highlight the data that was previously selected in the combobox,
and press the delete key to remove it, but after I move the mouse and
click on another field, the data that was just deleted re-appears in
the combobox? *I have three comboboxes and they are all doing this.
Also, if I keep trying to delete, eventually it accepts it? *I checked
everything, and I do not have anything coded that should be causing
this. Also, I noticed a few other posts with this problem, but found
no solution.
Each lookup table has referential integrity with cascading updates set
as 1 to many, and is tied to the main table (many). I’m not sure if
this is part of the problem?- Hide quoted text -

- Show quoted text -
Jul 24 '08 #4
Sorry, I misunderstood your problem. I think you can still go with the
keydown event of the combobox and check if the delete key was pressed.
If yes then flag it in a form level boolean variable. Then in the
Form's Current event if the combo_delete flag is set -- clear the
combobox field.

Dim comboDelete As Boolean

Private Sub Combo1_KeyDown(...)
If keycode = 46 then combodelete = True
End Sub

Private Sub Form1_Current()
If comboDelete = True Then
combo1 = ""
combodelete = False
End If
End Sub
Rich

*** Sent via Developersdex http://www.developersdex.com ***
Jul 24 '08 #5
Thank you Rich

I guess this problem is considered normal behavior? and not an issue
with my code/approach or
referential integrity issue? I guess I'll have to force the behavior
I'm looking for, and will follow your
suggestion.

Greg
On Jul 24, 1:07*pm, Rich P <rpng...@aol.comwrote:
Sorry, I misunderstood your problem. *I think you can still go with the
keydown event of the combobox and check if the delete key was pressed.
If yes then flag it in a form level boolean variable. *Then in the
Form's Current event if the combo_delete flag is set -- clear the
combobox field.

Dim comboDelete As Boolean

Private Sub Combo1_KeyDown(...)
If keycode = 46 then combodelete = True
End Sub

Private Sub Form1_Current()
If comboDelete = True Then
* combo1 = ""
* combodelete = False
End If
End Sub

Rich

*** Sent via Developersdexhttp://www.developersdex.com***
Jul 24 '08 #6
This worked Rick, and I placed the combo1="" logic in the OnExit event
of the combobox.
My new problem is I have about 18 comboboxes I have to write code for
to get this functionality, just
wondering if this undesired behavior is normal to begin with ?
Thanks Greg

On Jul 24, 2:47*pm, "Greg (code...@gmail.com)" <code...@gmail.com>
wrote:
Thank you Rich

I guess this problem is considered normal behavior? and not an issue
with my code/approach or
referential integrity issue? I guess I'll have to force the behavior
I'm looking for, and will follow your
suggestion.

Greg

On Jul 24, 1:07*pm, Rich P <rpng...@aol.comwrote:
Sorry, I misunderstood your problem. *I think you can still go with the
keydown event of the combobox and check if the delete key was pressed.
If yes then flag it in a form level boolean variable. *Then in the
Form's Current event if the combo_delete flag is set -- clear the
combobox field.
Dim comboDelete As Boolean
Private Sub Combo1_KeyDown(...)
If keycode = 46 then combodelete = True
End Sub
Private Sub Form1_Current()
If comboDelete = True Then
* combo1 = ""
* combodelete = False
End If
End Sub
Rich
*** Sent via Developersdexhttp://www.developersdex.com***- Hide quoted text -

- Show quoted text -
Jul 24 '08 #7
Actually, I just refined it one more time, and this seems to work:

Private Sub Combo1_KeyDown(...)
If keycode = 46 then combo1 = ""
End Sub

Thanks
Greg
On Jul 24, 3:24*pm, "Greg (code...@gmail.com)" <code...@gmail.com>
wrote:
This worked Rick, and I placed the combo1="" logic in the OnExit event
of the combobox.
My new problem is I have about 18 comboboxes I have to write code for
to get this functionality, just
wondering if this undesired behavior is normal to begin with ?

Thanks Greg

On Jul 24, 2:47*pm, "Greg (code...@gmail.com)" <code...@gmail.com>
wrote:
Thank you Rich
I guess this problem is considered normal behavior? and not an issue
with my code/approach or
referential integrity issue? I guess I'll have to force the behavior
I'm looking for, and will follow your
suggestion.
Greg
On Jul 24, 1:07*pm, Rich P <rpng...@aol.comwrote:
Sorry, I misunderstood your problem. *I think you can still go withthe
keydown event of the combobox and check if the delete key was pressed..
If yes then flag it in a form level boolean variable. *Then in the
Form's Current event if the combo_delete flag is set -- clear the
combobox field.
Dim comboDelete As Boolean
Private Sub Combo1_KeyDown(...)
If keycode = 46 then combodelete = True
End Sub
Private Sub Form1_Current()
If comboDelete = True Then
* combo1 = ""
* combodelete = False
End If
End Sub
Rich
*** Sent via Developersdexhttp://www.developersdex.com***-Hide quotedtext -
- Show quoted text -- Hide quoted text -

- Show quoted text -
Jul 24 '08 #8
>>

This worked Rick, and I placed the combo1="" logic in the OnExit event
of the combobox.
My new problem is I have about 18 comboboxes I have to write code for
to get this functionality, just
wondering if this undesired behavior is normal to begin with ?
Thanks Greg
<<

This is where Object Oriented Programming (OOP -- VB.Net) would come in
handy. For a situation like this you would use a Delegate -- which is
an interface for event functions (OOP speak here). You would assign the
same delegate to each combobox in a loop of comboboxes. I am basically
thinking aloud here to see how you could implement similar functionality
in VBA without having to write 18 keydown procedures for 18 comboboxes.
The alternative would be to write 18 keydown procedures. I am coming up
blank otherwise.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Jul 24 '08 #9
Rich

Never worked with OOP, but your explanation makes a lot of sense, and
demonstrates its value.
I created 18- 3line procedures. No big deal.
Thanks again for your help

Greg

On Jul 24, 4:04*pm, Rich P <rpng...@aol.comwrote:
This worked Rick, and I placed the combo1="" logic in the OnExit event
of the combobox.
My new problem is I have about 18 comboboxes I have to write code for
to get this functionality, just
wondering if this undesired behavior is normal to begin with ?

Thanks Greg
<<

This is where Object Oriented Programming (OOP -- VB.Net) would come in
handy. *For a situation like this you would use a Delegate -- which is
an interface for event functions (OOP speak here). *You would assign the
same delegate to each combobox in a loop of comboboxes. *I am basically
thinking aloud here to see how you could implement similar functionality
in VBA without having to write 18 keydown procedures for 18 comboboxes.
The alternative would be to write 18 keydown procedures. *I am coming up
blank otherwise.

Rich

*** Sent via Developersdexhttp://www.developersdex.com***
Jul 25 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Harlin Seritt | last post by:
I've created a ghetto-ized ComboBox that should work nicely for Tkinter (unfortunately no dropdown capabilities yet). I've found why it's such a pain in the @ss to create one. You have to...
3
by: Paul Fairless | last post by:
Customers table - contains Columns: CustID, Surname, Forename, TtlID Titles table - contains Columns: TtlID, Title TtlID is a Foreign Key in the Customers table. I have a Form frmCustomers...
14
by: Norm | last post by:
Hi, Each time the user selects an item from a combobox, I want that string to get appended to the values that were already selected. The result is that the combo is accumulating text each time...
0
by: rmatteson | last post by:
I am trying to figure out how to clear all items from a combobox (Access 2002). On my form, I have to comboboxes. Combobox 2 is populated with a set of child data dependent on the parent data...
0
by: Doug | last post by:
This is a repost of an item that I still cannot resolve. I have 3 combo boxes. The first leads to the second to the third. When I have selected a value in the second box, the third box shows...
4
by: jon f kaminsky | last post by:
Hi- I've seen this problem discussed a jillion times but I cannot seem to implement any advice that makes it work. I am porting a large project from VB6 to .NET. The issue is using the combo box...
1
by: amber | last post by:
I'm having an issue with a combobox that is making no sense to me at all. I have a form with several comboboxes/textboxes. The values in these boxes are based on a datarowview, which is based on...
3
by: Magnus | last post by:
Im using a set combobox (ComboBox1) to provide a selection of records from a database table. I have a typed dataset (DataSet1) that contains the typed datatable (DataTable1) that the combobox is...
1
by: Andrus | last post by:
I need to enter null value from combobox to business object property. My combobox datasource does not contain ValueMember with null value. So I tried to create combobox which stores null to bound...
2
by: kurtzky | last post by:
i created a form that should function as follows: i will enter a number in a textbox..then it should query from the database all the records which has that number..these records will have a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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?
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...

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.