作者david70222 (伭)
看板Visual_Basic
标题[VB6 ] 为什麽会一直重复?
时间Thu Aug 9 10:49:04 2007
Private Sub Command1_Click()
Dim sDT As String
Dim sID As String, sEmail As String
Dim sSQL As String
A = MsgBox("确认储存?", vbOKCancel + 32, "确认")
If A = 1 Then
Set Db = OpenDatabase(App.Path + "\account.mdb")
Set td = Db.TableDefs
Set fld = td("account").Fields
sDT = Format(Now, "yyyy/mm/dd hh:nn:ss")
s = "select * from [account]"
Set Re = Db.OpenRecordset(s)
Re.addnew
Re("建档日期") = sDT
Re("客户代码") = sID
Re("客户全称") = Text2.Text
Re("客户简称") = Text3.Text
Re("联络人") = Text5.Text
Re("负责人") = Text6.Text
Re("推荐人") = Text7.Text
Re("统一编号") = Text8.Text
Re("联络电话") = Text9.Text
Re("Fax") = Text10.Text
Re("帐单地址") = Text11.Text
Re("送货地址") = Text12.Text
Re("E-Mail") = sEmail
sID = Trim(Text1.Text)
sEmail = Trim(Text13.Text)
If InStr(sEmail, "@") = 0 Then
MsgBox "EMAIL格式错误", vbCritical, "错误"
Exit Sub
End If
sSQL = "select count(*) from Account where 客户代码='" & sID & "'"
If Not DoDataBase("query", sSQL) Then
MsgBox "客户代码重复", vbCritical, "错误"
Exit Sub
End If
sSQL = "insert into account (客户代码,E-MAIL) values('" & sID & "','" &
sEmail & "') "
DoDataBase "insert", sSQL
Re.Update
Re.Close
Else
End If
End Sub
Private Function DoDataBase(ByVal InType As String, ByVal InSQL As String) As
Boolean
Dim oCn As New ADODB.Connection
Dim oRs As New ADODB.Recordset
oCn.Open "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data
Source=C:\Documents and Settings\Mitsusi\Account.mdb"
If InType = "insert" Or InType = "update" Or InType = "delete" Then
oCn.Execute InSQL
Else
oRs.Open InSQL, oCn, 3, 3, 1
If oRs.RecordCount = 0 Then
DoDataBase = True
Else
DoDataBase = False
End If
End If
If oRs.State = 1 Then oRs.Close
If oCn.State = 1 Then oCn.Close
Set oRs = Nothing
Set oCn = Nothing
End Function
再输入资料的时後却会一直跳出客户代码重复不然就是EMAIL格式错误 囧"
麻烦请高手检查一下是哪边出了问题<(_ _)>
--
不会进步的新手(つ Д‵)
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.165.86.118
1F:推 fumizuki:If oRs.RecordCount = 0 Then 这个逻辑不正确吧 08/09 12:32