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

Combo boxes that delete

Hi all,
I have two unbound combo boxes on a form that I wuould like to use to
delete a record from a table. The two combo boxes find data from two
other tables through queries. When clicking on a command button to
delete the records it gives me an error of type mismatch. Here is the
code I am using. Any help would be grateful

DoCmd.SetWarnings False
Dim JobCode As String
Dim sempnum As String
Dim sstrsql As String
Dim rst As Recordset
sJobCode = Me![JobCodeCombo]
sempnum = Me![Combo45]

strsql = "DELETE FROM [Employee/Jobcodes] WHERE [empnum] =
" & sempnum And " [JobCode] = " & sJobCode

DoCmd.RunSQL strsql

Nov 13 '05 #1
4 1404
What data type are empnum and JobCode? If either is text, the value being
passed must be in quotes. For example, if empnum is numeric and JobCode is
text, you'd need:

strsql = "DELETE FROM [Employee/Jobcodes] WHERE [empnum] =
" & sempnum And " [JobCode] = " & Chr$(34) & sJobCode & Chr$(34)

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"Chuckles" <tm*****@new.rr.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Hi all,
I have two unbound combo boxes on a form that I wuould like to use to
delete a record from a table. The two combo boxes find data from two
other tables through queries. When clicking on a command button to
delete the records it gives me an error of type mismatch. Here is the
code I am using. Any help would be grateful

DoCmd.SetWarnings False
Dim JobCode As String
Dim sempnum As String
Dim sstrsql As String
Dim rst As Recordset
sJobCode = Me![JobCodeCombo]
sempnum = Me![Combo45]

strsql = "DELETE FROM [Employee/Jobcodes] WHERE [empnum] =
" & sempnum And " [JobCode] = " & sJobCode

DoCmd.RunSQL strsql

Nov 13 '05 #2
Thanks for the reply
They are both text so I tried this

strsql = "DELETE FROM [Employee/Jobcodes] WHERE [empnum] = " &
"sempnum" And " [JobCode] = " & "sJobCode"

I also set a breakpoint. empnum shows the correct string from sempnum
but jobcode shows jobcode = "" maybe the breakpoint didn't make it all
the way down the string? Still getting the type mismatch

Nov 13 '05 #3
Reread my suggestion. You aren't putting quotes around the variables: you're
passing the name of the variable the way you're doing it.

You can use

strsql = "DELETE FROM [Employee/Jobcodes] WHERE [empnum] = " & Chr$(34) &
sempnum & Chr$(34) & " And [JobCode] = " & Chr$(34) & sJobCode & Chr$(34)

or you can use

strsql = "DELETE FROM [Employee/Jobcodes] WHERE [empnum] = """ & sempnum &
""" And [JobCode] = """ & sJobCode & """"

(that's 3 double quotes before and after sempnum, 3 double quotes before
sJobCode and 4 after)

or you can use

strsql = "DELETE FROM [Employee/Jobcodes] WHERE [empnum] = '" & sempnum &
"' And [JobCode] = '" & sJobCode & "'"

Exagerated for clarity, this last one is

strsql = "DELETE FROM [Employee/Jobcodes] WHERE [empnum] = ' " & sempnum &
" ' And [JobCode] = ' " & sJobCode & " ' "

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)

"Chuckles" <tm*****@new.rr.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Thanks for the reply
They are both text so I tried this

strsql = "DELETE FROM [Employee/Jobcodes] WHERE [empnum] = " &
"sempnum" And " [JobCode] = " & "sJobCode"

I also set a breakpoint. empnum shows the correct string from sempnum
but jobcode shows jobcode = "" maybe the breakpoint didn't make it all
the way down the string? Still getting the type mismatch

Nov 13 '05 #4
Being that I am pretty new to sql statements I was shocked and amazed
when that worked. Thank you so much Doug. You rock!!!

Nov 13 '05 #5

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

Similar topics

0
by: Krisa | last post by:
Hello all, I just discovered something (stop me if you've heard this before....) that was causing me a significant performance hit when opening a form with subforms. To speed up loading the...
0
by: D Perron | last post by:
I am having a problem working with one combo box that is filtering another combo box. My table is tblResearch. There are two field in this table; one is and the other . I have a form called...
1
by: D Perron | last post by:
I am having a problem working with one combo box that is filtering another combo box. My table is tblResearch. There are two field in this table; one is and the other . I have a form called...
3
by: dmkeith2 | last post by:
I have a table for all my combox boxes. ID: AutoNumber ComboName: text ComboValue: text with no duplicates I have create a query based on this table. I have also created two forms based on...
14
by: Kevin | last post by:
A couple of easy questions here hopefully. I've been working on two different database projects which make use of multiple forms. 1. Where's the best/recommended placement for command buttons...
0
by: Tom | last post by:
I have some very strange issues with combo boxes on a tab control. Here's the scenario: I have a Windows Forms form that has a tab control on it, with two (2) tabs. Tab 2 happens to have a number...
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
1
by: Dave | last post by:
Hello all, First I'd like to apologize...This post was meant to be put in my previous post, but I tried many times without success to reply within my previous post. Now here goes... I have a...
2
by: Dave | last post by:
I have 3 tables of information feeding into 4 combo boxes on my main form (DR Form). I have as many list boxes (acting as text boxes) as there are fields in each one of the 3 tables. Once...
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: 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
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:
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
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...

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.