[VB6 ] 為什麼會一直重複?
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
推
08/09 12:32, , 1F
08/09 12:32, 1F
Visual_Basic 近期熱門文章
PTT數位生活區 即時熱門文章