I have an entry form that the user fills out(using textboxes), then clicks save and the entries are inserted into the database (using Insert Into). I can not figure out how to check the primary key field to see it is a duplicate, so I can pop up a message box to inform the user. I'm just learning to use vb with databases, so a detailed explaination would be greatly appreciated.
I'm not sure if it matters, but I have connected to the database via code and using ADO.
Here is my code for inserting the data, I want to do the check right before.
Public Sub Add()
Dim stSQL As String
Dim stPassword As String
Dim stCommPass As String
Dim stTransactionDate As String
Dim stClient As String
Dim stFound As String
With frmAdd
stPassword = .txtPassword
stCommPass = .txtCommPass
stClient = .txtClient
stSQL = "insert into cust"
stSQL = stSQL & "("
stSQL = stSQL & "Client"
stSQL = stSQL & ",Pass"
stSQL = stSQL & ",CommPass"
stSQL = stSQL & ""
stSQL = stSQL & " values"
stSQL = stSQL & "("
stSQL = stSQL & IsNVLString(stClient)
stSQL = stSQL & "," & IsNVLString(stPassword)
stSQL = stSQL & "," & IsNVLString(stCommPass)
stSQL = stSQL & ""
objAccessConnection.Execute stSQL
End With
MsgBox "Worked"
End Sub
Thanks for any help
Catrina
I'm not sure if it matters, but I have connected to the database via code and using ADO.
Here is my code for inserting the data, I want to do the check right before.
Public Sub Add()
Dim stSQL As String
Dim stPassword As String
Dim stCommPass As String
Dim stTransactionDate As String
Dim stClient As String
Dim stFound As String
With frmAdd
stPassword = .txtPassword
stCommPass = .txtCommPass
stClient = .txtClient
stSQL = "insert into cust"
stSQL = stSQL & "("
stSQL = stSQL & "Client"
stSQL = stSQL & ",Pass"
stSQL = stSQL & ",CommPass"
stSQL = stSQL & ""
stSQL = stSQL & " values"
stSQL = stSQL & "("
stSQL = stSQL & IsNVLString(stClient)
stSQL = stSQL & "," & IsNVLString(stPassword)
stSQL = stSQL & "," & IsNVLString(stCommPass)
stSQL = stSQL & ""
objAccessConnection.Execute stSQL
End With
MsgBox "Worked"
End Sub
Thanks for any help
Catrina