473,396 Members | 2,147 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,396 software developers and data experts.

Comboboxes and record deletion

I have two unbound combo boxes on one form and would like to select an
item in the first combo box which then brings up a list associated with
that item in the second combo box That part is all set up. however I
can't seem to figure out when i press a delete cmd button how to remove
that record from a table. I tried to write an sql statement but because
I'm new to all of this I can't seem to get those tricky parenthesis in
the right spots. Code would be greatly appreciated. Thanks for any help
in advance.

Nov 13 '05 #1
8 1336
Br
Chuckles wrote:
I have two unbound combo boxes on one form and would like to select an
item in the first combo box which then brings up a list associated
with that item in the second combo box That part is all set up.
however I can't seem to figure out when i press a delete cmd button
how to remove that record from a table. I tried to write an sql
statement but because I'm new to all of this I can't seem to get
those tricky parenthesis in the right spots. Code would be greatly
appreciated. Thanks for any help in advance.

Docmd.SetWarnings False
DoCmd.RunSQL "DELETE * FROM tblMyTable WHERE [lngMyID] = " &
Me![cboMyCombBoxBoundToID]
Docmd.SetWarnings True
--
regards,

Bradley

A Christian Response
http://www.pastornet.net.au/response
Nov 13 '05 #2
Thanks Bradley for the response. It still doesn't seem to be working
Here's the code. What am I a missing?

Private Sub Command24_Click()
On Error GoTo Err_Command24_Click

Dim MsgStr As String
Dim TitleStr As String

If IsNull(Me.Combo45) Then
MsgBox "No job codes selected...", vbExclamation
Exit Sub
End If

MsgStr = "Are You Sure You Want To Delete This Record?"
TitleStr = "Confirm Delete Record"
If MsgBox(MsgStr, vbYesNo, TitleStr) = vbNo Then
Exit Sub
End If

DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE * FROM [Employee/Jobcodes] WHERE
[empnum] = " & [Me.Combo45.Value]
DoCmd.SetWarnings False

DoCmd.SetWarnings True
MsgBox "Removed successfully...", vbInformation
DoCmd.SetWarnings True

Me.JobCodeCombo = Null
Me.JobCodeCombo.Requery
Me.JobCodeCombo = Me.JobCodeCombo.ItemData(0)
Exit_Command24_Click:
Exit Sub

Err_Command24_Click:
MsgBox Err.Description
Resume Exit_Command24_Click

End Sub

Nov 13 '05 #3
Sorry tried it again heres my sql statement:

DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE * FROM [Employee/Jobcodes] WHERE
[empnum] = " & Me![Combo45] And [JobCode] = "& me![jobcodecombo]"
DoCmd.SetWarnings True

I get a type mismatch error? Can't figure it out.

Nov 13 '05 #4
Br
Chuckles wrote:
Thanks Bradley for the response. It still doesn't seem to be working
Here's the code. What am I a missing? <>
DoCmd.RunSQL "DELETE * FROM [Employee/Jobcodes] WHERE
[empnum] = " & [Me.Combo45.Value]


Get this code line by itself and manually plug an ID into it, run it,
and see if the record is deleted.

Is [empnum] is actually a number and not text?

Is the ID the bound column in your combobox?

ps. Get into a good habit early :) ... use an exclamation, eg.
Me![Combo45], when refering to objects (use dot for
methods/properties).

<>
--
regards,

Bradley

A Christian Response
http://www.pastornet.net.au/response
Nov 13 '05 #5
Ok I commented everything out except this line of code after the
command button. I am still getting a type mismatch error. Thank you so
much for all of your help.

DoCmd.RunSQL "DELETE * FROM [Employee/Jobcodes] WHERE [empnum] = " &
Me![Combo45] And [JobCode] = "& me![jobcodecombo]"

Nov 13 '05 #6
oh and by the way neither combobox is bound because they look up data
from queries. As for empnum, it is text, as well as the jobcode it is
also text.

Nov 13 '05 #7
<os*****************@news-server.bigpond.net.au>
<11********************@g47g2000cwa.googlegroups.c om>
<qU*****************@news-server.bigpond.net.au>
<11*********************@o13g2000cwo.googlegroups. com>
Lines: 23
NNTP-Posting-Date: 07 Oct 2005 21:07:17 GMT
NNTP-Posting-Host: 81.187.1.21
X-Trace: 1128719237 news.aaisp.net.uk 38045 81.187.1.21
X-Complaints-To: aa*************@gradwell.net
Xref: number1.nntp.dca.giganews.com comp.databases.ms-access:836997

In article <11*********************@o13g2000cwo.googlegroups. com>,
Chuckles wrote:
DoCmd.RunSQL "DELETE * FROM [Employee/Jobcodes] WHERE [empnum] = " &
Me![Combo45] And [JobCode] = "& me![jobcodecombo]"


As a test, instead of using Combo box values, use actual values. E.g.:

DoCmd.RunSQL "DELETE * FROM [Employee/Jobcodes] WHERE [empnum] = '1'
And [JobCode] = '2';"

Assuming you have an empnum of 1 and a jobcode of 2 this should work.

Now replace the 1 and 2 with you combo box values:

DoCmd.RunSQL "DELETE * FROM [Employee/Jobcodes] WHERE [empnum] = '" &
Me![Combo45] & "' And [JobCode] = '" & me![jobcodecombo] & "';"

Hope that helps.

--
Roger

Nov 13 '05 #8
Br
Chuckles wrote:
oh and by the way neither combobox is bound because they look up data
from queries. As for empnum, it is text, as well as the jobcode it is
also text.


Ok. If they are text you must put quotes around them in your SQL
statement.

Oh, and you are missing a few & etc...

DoCmd.RunSQL "DELETE * FROM [Employee/Jobcodes] WHERE [empnum] = " &
Me![Combo45] And [JobCode] = "& me![jobcodecombo]"

Should be...

DoCmd.RunSQL "DELETE * FROM [Employee/Jobcodes] WHERE [empnum] = '" &
Me![Combo45] & "' And [JobCode] = '" & me![jobcodecombo] & "';"
--
regards,

Bradley

A Christian Response
http://www.pastornet.net.au/response
Nov 13 '05 #9

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

Similar topics

3
by: Chumley the Walrus | last post by:
IN my code behind .vb page for a delete records script (this also does a deletion confirmation with a javascript popup, this gets called on my front .aspx page with the datagrid), I'm not sure if...
0
by: johnson_cy | last post by:
I am using Access 2000. My main form has a record source of a table (employeeTbl with key of . It is filtering the record results. My subform and mainform have the link child/link master set...
5
by: Susan Bricker | last post by:
Any idea why a combobox would not populate? When the form is opened, it is opened with DOCMD.OPENFORM with selection criteria to send only those records for a particular dog (dogregnbr). The...
0
by: mjsterz | last post by:
I've been working with VB .NET for less than a year and this is the first time I've posted on one of these groups, so let me apologize beforehand if I'm being unclear, not posting my issue...
4
by: Phil Stanton | last post by:
Sorry to repost, but am having another look at deleting a record. I have a form (Member) and have removed all the event procedures associated with the Form (OnCurrent, OnDelete, OnActivate etc)...
3
by: BASSPU03 | last post by:
I had to present my DB today, but was granted a chance to fix something about it. In order to fix something, I added something...something that is giving me more trouble than it should. I have to...
3
by: Major Doug | last post by:
Hello: situation--I have a research database. Each record in the database consists of 10 fields. I used access97 to rack/stack my database; very easy in the beginning. I created a form with a...
1
vikas251074
by: vikas251074 | last post by:
Hello sir, I am facing some problem for which I am trying hard to solve it. But in vain. This programe is for View/Deletion. When I run program for first time, I select vlan from list and press...
0
by: thesti | last post by:
hello guru, actually this is a general Database question, i wonder how to implement record deletion in a table, if for example i delete a record in the 'Product' table, then when a user...
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: 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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.