类型不匹配错误 [英] Type Mismatch Error
问题描述
我收到类型不匹配错误当以下代码执行时。我想要通知用户是否尝试添加一个客户,其中
相同的FirstName,LastName,Address(line1)和City已经是
存在于文件中。
如果有匹配,请询问用户并取消记录添加,如果她看到
它是'是一个重复的客户。
我遇到线路延续,报价和延续问题
chracters,并注意到Access添加了一个在我的顶线。
这些领域没有任何尺寸;这是唯一的地方
他们被使用。
''确保用户在保存前输入新客户
私人Sub cmdClose_Click()
On Error GoTo Err_cmdClose_Click
''保存新的cust以便他们可以添加服装
Dim lngCustID As Long
''将新客户记录保存在tblCustomers中
''确保用户在保存前输入新客户
如果Me.Dirty = True那么
lngCustID = Me.txtCustID
DoCmd.RunCommand acCmdSaveRecord
''重新查询客户列表以查看新客户
表格!frmFindCustomer.lstCustomers.Requery
表格!frmFindCustomer.lstCustomers = lngCustID
结束如果
DoCmd.Close
Exit_cmdClose_Click:
退出Sub
Err_cmdClose_Click:
''如果用户输入相同的名字,姓氏,街道1和
城市作为一个存档,
''检查这是否真的是一个不同的客户(重复索引)
''如果这是一个错误。如果不同则允许保存;取消,如果错误
''如果回答不是,Me.undo并退出(认出它是'
dup-do not add)
''如果回答是YES,添加记录
如果Err.Number = 3022那么
如果MsgBox(客户 ;& Me.txtFirstName&""&
Me.txtLastName,"" _
&""& Me.txtAddress1 &""& Me.txtCity&存在。
_
&"你确定要添加这个吗? ?" _
& vbYesNoCancel + vbExclamation," Duplicate Customer")<>
vbYes然后
Me.Undo
GoTo Exit_cmdClose_Click
结束如果
结束如果
MsgBox Err.Number& " " &安培; Err.Description
恢复Exit_cmdClose_Click
结束子
非常感谢。
Sara
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_Click
'' 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.RunCommand acCmdSaveRecord
'' Requery the customer list to see the new customer as well
Forms!frmFindCustomer.lstCustomers.Requery
Forms!frmFindCustomer.lstCustomers = lngCustID
End If
DoCmd.Close
Exit_cmdClose_Click:
Exit Sub
Err_cmdClose_Click:
'' 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("Customer " & 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_Click
End If
End If
MsgBox Err.Number & " " & Err.Description
Resume Exit_cmdClose_Click
End Sub
Many thanks.
Sara
推荐答案
sara写道:
我得到的Type Mismatch Error当以下代码执行时。我试图通知用户她是否尝试添加具有相同FirstName,LastName,Address(line1)和City的客户,该客户已经存在于文件中。
/>
如果有匹配,请询问用户并取消记录添加,如果她看到它是一个重复的客户。
我遇到线路延续问题,引号和延续
chracters,并注意到Access添加了一个在我的顶线。
任何这些领域都没有维度;这是唯一使用它们的地方。
''确保用户在保存前输入新客户
私人子cmdClose_Click()
On Error GoTo Err_cmdClose_Click
''保存新的cust以便他们可以添加服装
Dim lngCustID As Long
''保存新的客户记录in tblCustomers
''确保用户在保存前输入新客户
如果Me.Dirty = True则
lngCustID = Me.txtCustID
DoCmd.RunCommand acCmdSaveRecord
''重新查询客户列表以查看新客户
表格!frmFindCustomer.lstCustomers.Requery
表格!frmFindCustomer.lstCustomers = lngCustID
结束如果
DoCmd.Close
Exit_cmdClose_Click:
退出Sub
Err_cmdClose_Click:
''如果用户输入相同的名字,姓氏,街道1和
城市如果这是一个错误,请检查以确定这是否真的是一个不同的客户(重复索引)
''。如果不同则允许保存;取消,如果错误
''如果回答不是,Me.undo并退出(认出它是
重复 - 不要添加)
''如果回复是是的,添加记录
如果Err.Number = 3022那么
如果MsgBox(客户& Me.txtFirstName&"&
我。 txtLastName,"" _
&""& Me.txtAddress1&""& Me.txtCity&存在。
_
&你确定要添加这个吗?_
& vbYesNoCancel + vbExclamation,Duplicate Customer)<>
vbYes然后
我。撤消
GoTo Exit_cmdClose_Click
结束如果
结束如果
MsgBox Err.Number& " " &安培; Err.Description
恢复Exit_cmdClose_Click
结束子
非常感谢。
Sara
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_Click
'' 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.RunCommand acCmdSaveRecord
'' Requery the customer list to see the new customer as well
Forms!frmFindCustomer.lstCustomers.Requery
Forms!frmFindCustomer.lstCustomers = lngCustID
End If
DoCmd.Close
Exit_cmdClose_Click:
Exit Sub
Err_cmdClose_Click:
'' 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("Customer " & 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_Click
End If
End If
MsgBox Err.Number & " " & Err.Description
Resume Exit_cmdClose_Click
End Sub
Many thanks.
Sara
哪条线路出错?
-
Smartin
Which line is throwing the error?
--
Smartin
对不起 - 如果MsgBox语句在调试器中突出显示。
Sara
Sorry - the If MsgBox statement is highlighted in the debugger.
Sara
如果MsgBox(客户& Me.txtFirstName&"&
Me.txtLastName,"" _
&""& Me.txtAddress1&" ; &&;& Me.txtCity&"存在。
_
&你确定要添加这个吗? _
& vbYesNoCancel + vbExclamation,Duplicate Customer)<>
vbYes然后
这是如果你指的是MsgBox?如果是这样,有一个逗号后面是
Me.txtLastName而没有&在引号之前。我没有看到引号
有多大帮助,我删除了它们并在下一行的第一组
引号内移动了逗号。我把所有东西搬到左边缘,所以希望
新闻阅读器不会换行。
此外,还有一个&而不是在vbYesNoCancel之前用逗号来表示这是下一个参数。
如果MsgBox(" Customer"& Me.txtFirstName& ;""& Me.txtLastName _
&","& Me.txtAddress1&""& Me.txtCity&存在。 _
&你确定要添加这个吗?,_
vbYesNoCancel + vbExclamation,Duplicate Customer)<> vbYes然后
-
Wayne Morgan
MS Access MVP
" sara" < SA ******* @ yahoo.com>在消息中写道
news:11 ********************** @ g49g2000cwa.googlegr oups.com ...
If MsgBox("Customer " & 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("Customer " & 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*******@yahoo.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
抱歉 - 如果调试器中突出显示了MsgBox语句。
Sara
Sorry - the If MsgBox statement is highlighted in the debugger.
Sara
这篇关于类型不匹配错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!