hello, im using vb6 with access 2007 (.mdb)
im using adodc connection.

my question, how to prevent if the data existed in my database.
i've put primary key in my database and i need an example like it's giving msgbox "data existed!"

anyone can help me?
thanks.

Recommended Answers

All 6 Replies

use .Find method to look to see for a record with the same value
the .NoMatch property will tell you whether the record exists or not

use .Find method to look to see for a record with the same value
the .NoMatch property will tell you whether the record exists or not

thanks, can u list some coding example?
im beginner, i need guide.
thanks again.

You can also use the "Recordcount, BOF or EOF" properties.

If Not Adodc1.BOF = True Then
'There is a record existing...
End If

You can also use the "Recordcount, BOF or EOF" properties.

If Not Adodc1.BOF = True Then
'There is a record existing...
End If
If Not Adodc1.Recordset.BOF = True Then
MsgBox "data existed!!", vbInformation
End If

Adodc1.Recordset.AddNew

Adodc1.Recordset!RegistrationNumber = cmbReg.Text
Adodc1.Recordset!RegistrationDate = txtDate.Text

Adodc1.Recordset.Update
MsgBox "Successfuly Save!!!", vbInformation

end sub

sir can u check my code?
thanks.

Your code looks fine although you will be adding a new record from one that already exist, that is incorrect I think.:)

Change your code to -

If Adodc1.Recordset.BOF = True Then
MsgBox "No data exist for this client. Please add a new record!!", vbInformation
End If
 
Adodc1.Recordset.AddNew
 
Adodc1.Recordset!RegistrationNumber = cmbReg.Text
Adodc1.Recordset!RegistrationDate = txtDate.Text
 
Adodc1.Recordset.Update
MsgBox "Successfuly Save!!!", vbInformation
 
end sub

Cavern, your code is OK except that you need an Exit Sub between lines 2 & 3

Also you don't strickly need the "= True" on line 1 since BOF returns a boolean value

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.