473,756 Members | 4,863 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Type Mismatch Error

I am getting "Type Mismatch Error" when the following code executes. I
am trying to notify the user if she attempts to add a customer with the
same FirstName, LastName, Address(line1) and City as one that already
exists on the file.

If there is a match, ask the user and cancel the record add if she sees
that it's a dup customer.

I had trouble with the line continuations, quotes and continuation
chracters, and noticed that Access added a " on the top line for me.

There are no dimensions for any of these fields; this is the only place
they are used.
' Makes sure the user entered a new customer before saving

Private Sub cmdClose_Click( )
On Error GoTo Err_cmdClose_Cl ick

' to save new cust so they can add garments

Dim lngCustID As Long

' saves the new customer record in tblCustomers

' Makes sure the user entered a new customer before saving

If Me.Dirty = True Then
lngCustID = Me.txtCustID
DoCmd.RunComman d acCmdSaveRecord
' Requery the customer list to see the new customer as well
Forms!frmFindCu stomer.lstCusto mers.Requery
Forms!frmFindCu stomer.lstCusto mers = lngCustID
End If

DoCmd.Close

Exit_cmdClose_C lick:
Exit Sub

Err_cmdClose_Cl ick:

' If the user enters the same first name, last name, street1 and
city as one on file,
' check to see if this is truly a different customer (dup index)
' of if this was an error. Allow save if different; cancel if error

' If response is NOT Yes, Me.undo and get out (recognize it's a
dup-do NOT add)
' If response is YES, add record

If Err.Number = 3022 Then
If MsgBox("Custome r " & Me.txtFirstName & " " &
Me.txtLastName, "" _
& " " & Me.txtAddress1 & " " & Me.txtCity & " exists. "
_
& " Are you sure you want to add this one too?" _
& vbYesNoCancel + vbExclamation, "Duplicate Customer") <>
vbYes Then
Me.Undo
GoTo Exit_cmdClose_C lick
End If
End If
MsgBox Err.Number & " " & Err.Description
Resume Exit_cmdClose_C lick

End Sub

Many thanks.
Sara

Nov 13 '05 #1
19 2084
sara wrote:
I am getting "Type Mismatch Error" when the following code executes. I
am trying to notify the user if she attempts to add a customer with the
same FirstName, LastName, Address(line1) and City as one that already
exists on the file.

If there is a match, ask the user and cancel the record add if she sees
that it's a dup customer.

I had trouble with the line continuations, quotes and continuation
chracters, and noticed that Access added a " on the top line for me.

There are no dimensions for any of these fields; this is the only place
they are used.
' Makes sure the user entered a new customer before saving

Private Sub cmdClose_Click( )
On Error GoTo Err_cmdClose_Cl ick

' to save new cust so they can add garments

Dim lngCustID As Long

' saves the new customer record in tblCustomers

' Makes sure the user entered a new customer before saving

If Me.Dirty = True Then
lngCustID = Me.txtCustID
DoCmd.RunComman d acCmdSaveRecord
' Requery the customer list to see the new customer as well
Forms!frmFindCu stomer.lstCusto mers.Requery
Forms!frmFindCu stomer.lstCusto mers = lngCustID
End If

DoCmd.Close

Exit_cmdClose_C lick:
Exit Sub

Err_cmdClose_Cl ick:

' If the user enters the same first name, last name, street1 and
city as one on file,
' check to see if this is truly a different customer (dup index)
' of if this was an error. Allow save if different; cancel if error

' If response is NOT Yes, Me.undo and get out (recognize it's a
dup-do NOT add)
' If response is YES, add record

If Err.Number = 3022 Then
If MsgBox("Custome r " & Me.txtFirstName & " " &
Me.txtLastName, "" _
& " " & Me.txtAddress1 & " " & Me.txtCity & " exists. "
_
& " Are you sure you want to add this one too?" _
& vbYesNoCancel + vbExclamation, "Duplicate Customer") <>
vbYes Then
Me.Undo
GoTo Exit_cmdClose_C lick
End If
End If
MsgBox Err.Number & " " & Err.Description
Resume Exit_cmdClose_C lick

End Sub

Many thanks.
Sara


Which line is throwing the error?

--
Smartin
Nov 13 '05 #2
Sorry - the If MsgBox statement is highlighted in the debugger.

Sara

Nov 13 '05 #3
If MsgBox("Custome r " & Me.txtFirstName & " " &
Me.txtLastName, "" _
& " " & Me.txtAddress1 & " " & Me.txtCity & " exists. "
_
& " Are you sure you want to add this one too?" _
& vbYesNoCancel + vbExclamation, "Duplicate Customer") <>
vbYes Then

Is this the If MsgBox you are referring to? If so, there is a comma after
Me.txtLastName and no & before the quotes. I don't see where the quotes
there help much, I removed them and moved the comma inside the first set of
quotes on the next line. I moved everything to the left margin so hopefully
the newsreader won't wrap the lines.

Also, there is an & instead of a comma before the vbYesNoCancel to indicate
that this is the next argument.

If MsgBox("Custome r " & Me.txtFirstName & " " & Me.txtLastName _
& ", " & Me.txtAddress1 & " " & Me.txtCity & " exists. " _
& " Are you sure you want to add this one too?", _
vbYesNoCancel + vbExclamation, "Duplicate Customer") <> vbYes Then
--
Wayne Morgan
MS Access MVP
"sara" <sa*******@yaho o.com> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.com.. .
Sorry - the If MsgBox statement is highlighted in the debugger.

Sara

Nov 13 '05 #4
sara wrote:
Sorry - the If MsgBox statement is highlighted in the debugger.

Sara


If MsgBox("Custome r " & Me.txtFirstName & " " &
Me.txtLastName, "" _
& " " & Me.txtAddress1 & " " & Me.txtCity & " exists. "
_
& " Are you sure you want to add this one too?" _
& vbYesNoCancel + vbExclamation, "Duplicate Customer") <>
vbYes Then
Me.Undo
GoTo Exit_cmdClose_C lick
End If

OK here's something to look at: you have a comma on the second line.
This separates the MsgBox prompt from the buttons. I don't think you
meant to do that there. Undoubtedly this is where the Then you are
lacking a comma to separate what looks like the prompt from the buttons.

To keep things straight I would suggest building up a few string
arguments to pass to the MsgBox function, ala

Dim sPrompt as String
Dim iButtons as Integer
Dim sTitle as String

sPrompt = "Customer " & Me.foo & " bar"
iButtons = vbYesNoCancel Or vbExclamation
sTitle = "Duplicate"

If MsgBox(sPrompt, iButtons, sTitle) <> vbYes Then

etc.

HTH
--
Smartin
Nov 13 '05 #5
Smartin wrote:
sara wrote:
Sorry - the If MsgBox statement is highlighted in the debugger.

Sara

If MsgBox("Custome r " & Me.txtFirstName & " " &
Me.txtLastName, "" _
& " " & Me.txtAddress1 & " " & Me.txtCity & " exists. "
_
& " Are you sure you want to add this one too?" _
& vbYesNoCancel + vbExclamation, "Duplicate Customer") <>
vbYes Then
Me.Undo
GoTo Exit_cmdClose_C lick
End If

OK here's something to look at: you have a comma on the second line.
This separates the MsgBox prompt from the buttons. I don't think you
meant to do that there. Undoubtedly this is where the


oops... meant to say "Undoubtedl y this is where the error is cropping up".
Then you are
lacking a comma to separate what looks like the prompt from the buttons.

To keep things straight I would suggest building up a few string
arguments to pass to the MsgBox function, ala

Dim sPrompt as String
Dim iButtons as Integer
Dim sTitle as String

sPrompt = "Customer " & Me.foo & " bar"
iButtons = vbYesNoCancel Or vbExclamation
sTitle = "Duplicate"

If MsgBox(sPrompt, iButtons, sTitle) <> vbYes Then

etc.

HTH

--
Smartin
Nov 13 '05 #6
"sara" <sa*******@yaho o.com> wrote in
news:11******** **************@ f14g2000cwb.goo glegroups.com:
If Me.Dirty = True Then
lngCustID = Me.txtCustID
DoCmd.RunComman d acCmdSaveRecord


Your question has actually been answered later, but I'd thought I'd
make a ocmment on codeing style.

First, since Me.Dirty is a property of the form and returns a
Boolean value, you don't need to compare it to True:

If Me.Dirty Then

Last of all, rather counterintuitiv ely (or so it has always seemed
to me), the .Dirty property of a form is actually not read only. If
you set it to False, it saves the form. So, the way I'd code the
snippet above is:

If Me.Dirty Then
lngCustID = Me!txtCustID
Me.Dirty = False

I won't discuss here the fact that I use ! instaed of . for
references to controls -- that's a long thread that we just had a
couple of weeks ago!

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 13 '05 #7
David W. Fenton wrote:
"sara" <sa*******@yaho o.com> wrote in
news:11******** **************@ f14g2000cwb.goo glegroups.com:

If Me.Dirty = True Then
lngCustID = Me.txtCustID
DoCmd.RunComman d acCmdSaveRecord

Your question has actually been answered later, but I'd thought I'd
make a ocmment on codeing style.

First, since Me.Dirty is a property of the form and returns a
Boolean value, you don't need to compare it to True:

If Me.Dirty Then

Last of all, rather counterintuitiv ely (or so it has always seemed
to me), the .Dirty property of a form is actually not read only. If
you set it to False, it saves the form. So, the way I'd code the
snippet above is:

If Me.Dirty Then
lngCustID = Me!txtCustID
Me.Dirty = False

I won't discuss here the fact that I use ! instaed of . for
references to controls -- that's a long thread that we just had a
couple of weeks ago!


And to expand on David's response - you want to use Me.Dirty = False because it is very
explicit about what it is going to do. It will save a record on the current form (Me).

Using DoCmd.RunComman d acCmdSaveRecord will save a record on whatever form has the current
focus. That might not be the form you expect it to be. There is no ambiguity if you use
"Me" so using Me.Dirty = False will prevent the rare occasion where another object gets
the focus and you save a record on a form you didn't expect.

The DoCmd.Close is a similar potential landmine. Without any parameters it closes whatever
has the current focus. Its much better to be very explicit that you want to close the form
that the code is running in by using:

DoCmd.Close acForm, Me.Name

Good luck on your project.

--
'---------------
'John Mishefske
'---------------
Nov 13 '05 #8
John Mishefske wrote:
And to expand on David's response - you want to use Me.Dirty = False because it is very
explicit about what it is going to do. It will save a record on the current form (Me).

Using DoCmd.RunComman d acCmdSaveRecord will save a record on whatever form has the current
focus. That might not be the form you expect it to be.
Good luck on your project.


Could you explain this further, please? Sara's "DoCmd.RunComma nd
acCmdSaveRecord " appears in a Private Sub (Private Sub
cmdClose_Click( )) seeiminglt in a Form Module in this context:

If Me.Dirty = True Then
lngCustID = Me.txtCustID
DoCmd.RunComman d acCmdSaveRecord

In what situations will this command run when the form in which it
resides (the Me form) does not have the focus?

What is the code in an Object other than the Form1 module to call
Form1's cmdClose_Click( )?
What is similar code to do so while Form2 or other form has the focus?

Nov 13 '05 #9
Thank you - it works!

I think my confustion is around when to use the & on a continuation
line and when not to. Is there anything on the web on this? I have
looked around in Help and the web and the 3 books I have and found
nothing.

I have had to use the continuation character AND the & AND quotes at
the end of each line and the beginning of the next when building a SQL
string (like "Where" clause) in code. It appears, however that the
extra ampersand and quotes are only needed when doing continuations of
text that should be in quotes - or something like that?

The comma was my error.
Thanks
Sara

Nov 13 '05 #10

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

Similar topics

4
10637
by: leslie_tighe | last post by:
Hello, I have a method on a com+ object that is returning an array of objects. I know the array is popluated as calls to check the ubound and lbound show valid values. However, any calls to get the value of a cell in the array results in a type mismatch error.
4
11967
by: Mike | last post by:
I am getting a type mismatch error when I do a bulk insert. ---Begin Error Msg--- Server: Msg 4864, Level 16, State 1, Line 1 Bulk insert data conversion error (type mismatch) for row 1, column 14 (STDCOST). ---End Error Msg--- The STDCOST is set to decimal (28,14) and is a formatted in Access as a number, single with 14 decimal. I don't know why I would be getting a Type
6
3906
by: shan | last post by:
What is the meaning for the error expression syntax and type mismatch error.I am using turbo c++.can anybody correct the errors in the folowing program. Following program is to find matrix addition. Thanks in advance. #include<stdio.h> int rows,cols,a,b;
1
2045
by: jodyblau | last post by:
I am getting a type mismatch message under strange circumstances. Here's whats going on: 1. I have split the database into a front end and a back end. 2. I have compiled the project. 3. I update the linked tables and then make an mde file. 4. When I use the mdb file, everything seems to work fine.
2
1939
by: Rehan | last post by:
Hi there! Please help me out here. I am an inch away from completing my assignment. I am very new to VBA but i have very less time to be efficient at it. I am getting a type mismatch error when i click the button whose code is:
5
2848
by: kjworm | last post by:
Hello Everyone, I have been fighting with a type mismatch error for many hours today and I can't seem to find what the problem is. Hopefully it is more than a missing apostrophe! I have isolated each SQL statement using a MsgBox and then input that exact code as a Query in access which works. I'm using Access 97 on Windows XP. My code is below: Dim strKaizen As String strKaizen = "UPDATE KaizenEvents SET(TeamLeader)= '" & & "' WHERE...
7
5363
by: Mike | last post by:
Type Mismatch error I recieve a type mismatch error on the following line of code which is based on a specific date. It does NOT break on all records only "some". The dates for the records that ARE breaking are no different then the ones that are NOT breaking... Any hely is appreciated... Mike CODE:
5
9955
by: Lara1 | last post by:
Hi, I'm a total beginner to VBA, so please bear with me if I seem a bit dense. What I'm Trying to Achieve I'm trying to write a procedure in Excel, which is supposed to - look at the pH values stored in column E, row by row - compare this to a threshold value of 5 - enter a string ("pH range C") in column K, if the value in column E exceeds 5.
1
4041
by: sharbha | last post by:
I am experiencing a VBScript runtime error. The error message is: "(0x800A000D)Type mismatch error" Here is my code: <% dim temp temp=session("items") session("count")=session("count")+1 redim preserve items(session("count"))
0
9152
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9930
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9716
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9716
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9571
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8569
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3185
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2542
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.