the followings ar my code:
Private Sub 訂_Click()
Dim IntUnit As Integer
Dim AmtUnit As Integer
Dim theConnection As New ADODB.Connection
Dim strSQL As String
IntUnit = txtUnit
IntAmt = txtAmt
strSQL = "INSERT INTO OrderTable"
strSQL = strSQL & "(Unit, Amt)"
strSQL = strSQL & "VALUES("
strSQL = strSQL & "&IntUnit&"
strSQL = strSQL & "&IntAmt&"
With theConnection
.Open "DSN=OrderDSN"
.Execute strSQL
.Close
End With
Set theConnection = Nothing
strSQL = ""
End Sub
when i press F5, it said runtime error '13'. type mismatch on (Dim IntUnit As Integer). So what is my problem? is anyone can help me?
Private Sub 訂_Click()
Dim IntUnit As Integer
Dim AmtUnit As Integer
Dim theConnection As New ADODB.Connection
Dim strSQL As String
IntUnit = txtUnit
IntAmt = txtAmt
strSQL = "INSERT INTO OrderTable"
strSQL = strSQL & "(Unit, Amt)"
strSQL = strSQL & "VALUES("
strSQL = strSQL & "&IntUnit&"
strSQL = strSQL & "&IntAmt&"
With theConnection
.Open "DSN=OrderDSN"
.Execute strSQL
.Close
End With
Set theConnection = Nothing
strSQL = ""
End Sub
when i press F5, it said runtime error '13'. type mismatch on (Dim IntUnit As Integer). So what is my problem? is anyone can help me?
文章標籤
全站熱搜

你好: 在資料庫中,可能unit的型態,不是integer,去檢查一下喔!
hi, thx for help. but the type in access and the type in VB is the same..... so do u know whats the problem? Thanks
(1).組成sql語法 strSQL = "INSERT INTO OrderTable" strSQL = strSQL & "(Unit, Amt)" strSQL = strSQL & "VALUES(" strSQL = strSQL & IntUnit & "," strSQL = strSQL & IntAmt & ")" (2).看不到IntAmt的宣告且沒用到AmtUnit變數,這裡是不是打錯了呢? (3).在執行這段程式時,txtUnit及txtAmt的內容是什麼? 可能出錯的問題點蠻多的,建議您在開頭加上Option Explicit,且用Ctrl+F5執行程式,讓一些錯誤提早浮現後,才有辦法專心在資料庫的操作上。
thx. i hv a try 1st
i try ur suggestions b4.....but i cant put "," at the end of IntUnit , it said Compile error. Expected:end of statement If without "," and just ") at the end of IntAmt, it said syntax error when i run the program strSQL = strSQL & IntUnit & "," strSQL = strSQL & IntAmt & ") both txtInt and txtAmt is the textbox name where i enter int and amt integer. Thx Doug
strSQL = strSQL & IntAmt & ") <--您的語法 strSQL = strSQL & IntAmt & ")" <--我的語法 是不是這個雙引號的關係?
thx.