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

Deleting a selection from a combobox

173 100+
hi,

has any1 got any examples i can look at for the following:




[PHP]A delete button that deletes the item selected in the combobox [/PHP]




i need it urgently???????please

or even any code!!!!
Dec 6 '06 #1
18 1998
nico5038
3,080 Expert 2GB
Assuming the combobox named "cmbX" has a recordsource like:

select code, description from tblX

You can code a button with:
Expand|Select|Wrap|Line Numbers
  1. '  check selection made
  2. IF len(nz(me.cmbX)) > 0 then
  3.     ' yes, delete
  4.     currentdb.execute ("delete * from tblX where code=" & me.cmbX)
  5.     me.cmbX.requery
  6. endif
  7.  
Getting the idea ?

Nic;o)
Dec 6 '06 #2
Beany
173 100+
ive tried your idea Nico....

the combobox is called Combo2
the row source of Combo2 is:

[PHP]SELECT [tab_main].[username] FROM tab_main ORDER BY [username];[/PHP]

the code im using for the delete button is:

[PHP]Private Sub Command11_Click()
On Error GoTo Err_Command11_Click

If Len(Nz(Me.Combo2)) > 0 Then

CurrentDb.Execute ("delete * from tab_main where code=" & Me.Combo2)
Me.Combo2.Requery
End If
Exit_Command11_Click:
Exit Sub

Err_Command11_Click:
MsgBox Err.Description
Resume Exit_Command11_Click

End Sub[/PHP]

but im getting the following error message:

Syntax error (missing operator) in query expression 'code=Adam Beaky'.

Adam Beaky is an example selected from combobox
Dec 8 '06 #3
nico5038
3,080 Expert 2GB
Hmm, I assumed the code was numeric, for a string embedding in single quotes is mandatory like:

"SELECT * FROM x WHERE code='" & me.combobox & "'")

Or when you have names wih an embedded quote use:

"SELECT * FROM x WHERE code=" & chr(34) & me.combobox & chr(34))

Nic;o)
Dec 8 '06 #4
Beany
173 100+
Ok Nico ive changed it to the following:

[PHP]Private Sub Command11_Click()
On Error GoTo Err_Command11_Click

If Len(Nz(Me.Combo2)) > 0 Then

CurrentDb.Execute ("SELECT * FROM tab_main WHERE code='" & Me.Combo2 & "'")

Me.Combo2.Requery
End If
Exit_Command11_Click:
Exit Sub

Err_Command11_Click:
MsgBox Err.Description
Resume Exit_Command11_Click

End Sub[/PHP]

am i doing sumat wrong?

im getting a error message saying Cannot execute a select query..

is it possible if you could please modify this code for me?
Dec 8 '06 #5
NeoPa
32,556 Expert Mod 16PB
Ok Nico ive changed it to the following:

[PHP]Private Sub Command11_Click()
On Error GoTo Err_Command11_Click

If Len(Nz(Me.Combo2)) > 0 Then

CurrentDb.Execute ("SELECT * FROM tab_main WHERE code='" & Me.Combo2 & "'")

Me.Combo2.Requery
End If
Exit_Command11_Click:
Exit Sub

Err_Command11_Click:
MsgBox Err.Description
Resume Exit_Command11_Click

End Sub[/PHP]

am i doing sumat wrong?

im getting a error message saying Cannot execute a select query..

is it possible if you could please modify this code for me?
Yes Beany ;).
But it's a simple fix.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command11_Click()
  2. On Error GoTo Err_Command11_Click
  3.  
  4. If Len(Nz(Me.Combo2)) > 0 Then
  5.  
  6.     CurrentDb.Execute ("DELETE * FROM tab_main WHERE code='" & Me.Combo2 & "'")
  7.  
  8.     Me.Combo2.Requery
  9. End If
  10. Exit_Command11_Click:
  11.     Exit Sub
  12.  
  13. Err_Command11_Click:
  14.     MsgBox Err.Description
  15.     Resume Exit_Command11_Click
  16.  
  17. End Sub
(See post #2 for what Nico originally suggested.)
Dec 8 '06 #6
Beany
173 100+
Neo ive inserted the code what you modified (select -> delete(thanks))....

but when i select a name from the combobox and click the delete button i get the following message:

[HTML]Too few parameters. Expected 1[/HTML]

why is that?
Dec 9 '06 #7
nico5038
3,080 Expert 2GB
This implies that you use an unknown fieldname.
You will have to change the "code" into the fieldname from your table.

Nic;o)
Dec 9 '06 #8
Beany
173 100+
Sorry about this, but i dont really understand what your suggesting?


(i bet you must be sick of me):)
Dec 9 '06 #9
MMcCarthy
14,534 Expert Mod 8TB
Sorry about this, but i dont really understand what your suggesting?


(i bet you must be sick of me):)
In your table tab_main do you have a field named code?
Dec 9 '06 #10
Beany
173 100+
No Mary, there is no field named 'code'..........

ive got the following fields:

[PHP]userID, number, username,cost_centre,phone_model,imei,sim_no,puk_c ode,date_issued,notes,tariff, roam, call_int[/PHP]
Dec 9 '06 #11
MMcCarthy
14,534 Expert Mod 8TB
No Mary, there is no field named 'code'..........

ive got the following fields:

[PHP]userID, number, username,cost_centre,phone_model,imei,sim_no,puk_c ode,date_issued,notes,tariff, roam, call_int[/PHP]
Which one corresponds to the value in the Combo2 combo box?
Dec 9 '06 #12
Beany
173 100+
IT WORKS.........................

i changed code to username................................ and it works...........

can i kiss you Mary? :)
thank you very much............

last thing.... is there a way of adding a warning message to this?

ie are you sure you want to delete this user?
Dec 9 '06 #13
MMcCarthy
14,534 Expert Mod 8TB
Try this ...

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command11_Click()
  2. On Error GoTo Err_Command11_Click
  3. Dim rslt As Integer
  4.  
  5.    If Len(Nz(Me.Combo2)) > 0 Then
  6.       rslt=Msgbox("Are you sure you wish to delete " & Me.Combo2 & " from the table?", vbYesNo)
  7.       If rslt=vbYes Then
  8.          CurrentDb.Execute ("DELETE * FROM tab_main WHERE username='" & Me.Combo2 & "'")
  9.          Me.Combo2.Requery
  10.       End If
  11.    End If
  12.  
  13. Exit_Command11_Click:
  14.  
  15.     Exit Sub
  16.  
  17. Err_Command11_Click:
  18.  
  19.     MsgBox Err.Description
  20.     Resume Exit_Command11_Click
  21.  
  22. End Sub 
  23.  
Mary
Dec 10 '06 #14
Beany
173 100+
perfecto............

THANK YOU VERY MUCH............... GOD Bless you........

you know ur 5hit!!!!!!
Dec 10 '06 #15
MMcCarthy
14,534 Expert Mod 8TB
perfecto............

THANK YOU VERY MUCH............... GOD Bless you........

you know ur 5hit!!!!!!
You can also use a message box like this around your insert statement in your other question to allow the user to cancel the operation.

Mary
Dec 10 '06 #16
Beany
173 100+
excellent..... is it just a simple copy and paste job lol (with the obvious changes?)
Dec 10 '06 #17
NeoPa
32,556 Expert Mod 16PB
excellent..... is it just a simple copy and paste job lol (with the obvious changes?)
That really depends on what's 'obvious'.
The answer should be yes, but try it and see.
Repost if you can't get it to work for yourself. You should have picked up quite a lot about all this by now :).
Dec 10 '06 #18
Beany
173 100+
true true lol lol im genious now :) :)
Dec 10 '06 #19

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

Similar topics

1
by: Steve | last post by:
I have a continuous form with several unbound comboboxes in the form header. The comboboxes are used to provide criteria for the SQL of the form. The code behind the form looks like: Public Sub...
2
by: Steve Claflin | last post by:
Is there a way to have multiple keystrokes select the first matching item in a combobox? For instance, in the Doe family members combobox, typing jo would go to Jane on the j, then John on the o...
1
by: Simon | last post by:
Dear reader, With a combobox I can go to a selected record picked in the pull down list. And in the same time the record navigation field shows the selected record number from the...
2
by: jen | last post by:
i have select query that returns multiple records and populates a combobox/pulldown. once a selection from the pulldown is selected, i need to reference two or three fileds from the previous...
5
by: njb35 | last post by:
Hi all I'm beginning my foray from VBA into VB 2005 Express, and enjoying some of the efficiencies it provides! I'm stuck with some dataset handling however that I _think_ can be automated but...
0
by: jimmarq | last post by:
I am creating a windows form application in VB.NET 2.0. I have a datagridview, and one of the columns ("SelectorColumn") is a Combobox. The combobox values come from a dataset, and the column is...
1
by: BSTAFFORD | last post by:
I need help. I have a form with a 5 comboboxes. the form also contains a subform query with the saved records from those 5 combobox categories. What I'd like to happen is as a new record is...
1
by: Rosie | last post by:
I have a main form with header info w/ 'tHeader' as the control source. I have a subform with 'tDetail' as a control source. They're strung together by a field named MA_ID. This works...
0
by: pavanip | last post by:
Hi, I am facing problem with combobox in gridview.I have used combobox in gridview and i am binding data to gridview combobox from database. If i click 2 times on combobox then it is showing the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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
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: 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:
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...

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.