954,152 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Using RecordsAffected as a parameter

SearchString = "SELECT * FROM Breakdown WHERE BFrom = " & txtFrom.Text ' & " AND BTo = " & txtTo.Text
Dim Con As New OleDbConnection(BCalc_ConnectionString)
Dim Search As New OleDbCommand(SelectSearchString, Con)


I want to stop users from being able to save a duplicate record in my Access database. I thought of using RecordsAffected, but I can't figure out how to get it to work.

That's how I've started. I want to be able to use the result of the RecordsAffected as a parameter in an IF statement so that

IF Search.records affected = 0 THEN Insert records
 ELSE Display msgbox telling user that duplicate records aren't allowed.


Please Help...

Estella
Junior Poster in Training
99 posts since Jan 2008
Reputation Points: 64
Solved Threads: 7
 

see this code :

Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\MyDB.mdb;")
cn.Open()
cmd = New OleDbCommand("SELECT * FROM Breakdown WHERE BFrom = '" & txtFrom.Text & "'", cn)
dr = cmd.ExecuteReader
If dr.Read()
  MsgBox "Matching Records Found"
  'write whatevr code u want here
Else
  MsgBox "Data not found"
End If
dr.Close()
cn.Close()
Jx_Man
Nearly a Senior Poster
3,328 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
 

thank for great suggestion
it help me much... :)

Estella
Junior Poster in Training
99 posts since Jan 2008
Reputation Points: 64
Solved Threads: 7
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You