I am trying to use Insert Statement which is one of the field(format = Number) in Access = 0. My program does not understand data which is one of the field = 0. Can you help me to solve the problem.
I am appreciate for your help !!!!!!!
Printable View
I am trying to use Insert Statement which is one of the field(format = Number) in Access = 0. My program does not understand data which is one of the field = 0. Can you help me to solve the problem.
I am appreciate for your help !!!!!!!
If it exists, then you cannot insert it. Otherwise, it may start with 1, so I'd try that first.
I have to insert 2 way : if it exist or not.
Post your code around the INSERT (and use CODE TAGS, please).
Code:
Dim diem as Double
If (ws.Range("F" & i).Value = NULL) Then
diem = 0
Else
diem = ws.Range("F" & i).Value
End If
con.Execute "INSERT INTO SV([No],MSSV,MaLop,Ho,Ten,Diem,HanhKiem,[User],Status,[Date]) VALUES ('" & rs("MaxField") + 1 & "','" & ws.Range("C" & i).Value & "','" & ws.Range("A" & i).Value & "','" & ws.Range("D" & i).Value & "','" & ws.Range("E" & i).Value & "','" & ws.Range("F" & i).Value & "','" & tenUser & "','" & "-1" & "','" & NgayGioDangNhap & "')"
I can't even begin to understand the question, you'll need to do a better job of explaining what you are trying to do and what problem you are having. Also need to tell us what field and what the data type is of that field in the database.
Try printing the value of the query, and putting that into ACCESS
Code:Dim Query as String
Query = "INSERT INTO SV([No],MSSV,MaLop,Ho,Ten,Diem,HanhKiem,[User],Status,[Date]) VALUES ('" & rs("MaxField") + 1 & "','" & ws.Range("C" & i).Value & "','" & ws.Range("A" & i).Value & "','" & ws.Range("D" & i).Value & "','" & ws.Range("E" & i).Value & "','" & ws.Range("F" & i).Value & "','" & tenUser & "','" & "-1" & "','" & NgayGioDangNhap & "')"
Debug.Print Query
stop
' after it works in access, use this:
con.Execute Query ' and it should work