Error checking for an existing record

Thread Solved

Join Date: Oct 2009
Posts: 23
Reputation: Israelsimba is an unknown quantity at this point 
Solved Threads: 0
Israelsimba Israelsimba is offline Offline
Newbie Poster

Error checking for an existing record

 
0
  #1
20 Days Ago
i am trying to make sure that one record is not entered twice into the same database but the code i am using is giving me an error
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Set ri = deSub.conn.Execute("SELECT* FROM individualsubs WHERE firstname = '" & txtfname.Text & "' AND surname = '" & txtsurname.Text & "'")
  2. If ri.EOF = True Then
  3.  
  4. ri.AddNew
  5. ri.Fields("firstname") = txtfname.Text
  6. ri.Fields("surname") = txtsurname.Text
  7. ri.Fields("numberofcopies") = x * Y
  8. ri.Fields("copiesout") = txtcopies.Text
  9. ri.Fields("copiesremaining") = x * Y
  10. ri.Update
  11. Else......
the error i am getting is
current recordset does not support updating. This might be a limitation of the provider or the selected locktype lock type
but i am using adlockoptimistic as shown below which suports updating...
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. With ri
  2. .ActiveConnection = deSub.conn
  3. .LockType = adLockOptimistic
  4. .Source = "select * from individualsubs"
  5. .Open
  6. End With
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 23
Reputation: Israelsimba is an unknown quantity at this point 
Solved Threads: 0
Israelsimba Israelsimba is offline Offline
Newbie Poster
 
0
  #2
20 Days Ago
since i found roblems with adding a new record after checking if it was existant i then tried a another method but its giving me an error. the code is
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. deSub.conn.Execute ("INSERT INTO individualsubs VALUES (clientnumber = " & txtcopies.Text & ", surname = '" & txtsurname.Text & "', firstname = '" & txtfname.Text & "', nowdate = '" & DTPicker2.Value & "', numberofcopies = " & x * Y & ", copiesout = " & txtcopies.Text & ", copiesremaining = " & x * Y & ")")

one or more reqired fields is missing in the requested ordinal
what could be wrong with my code here
thatnx
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 811
Reputation: vb5prgrmr will become famous soon enough vb5prgrmr will become famous soon enough 
Solved Threads: 147
vb5prgrmr vb5prgrmr is offline Offline
Practically a Posting Shark
 
1
  #3
20 Days Ago
Okay, in your first post you set the lock type with the second code snippet but I don't see it in the first code snippet, which means if you have not explicitly set it, it defaults back to its default settings, which might be your problem.

Now, in your second post, you have formatted the insert statement incorrectly. Presently it looks more like an update statement but that is neither here nor there or the answer to your problem. So, a properly formatted insert statement looks like this...

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. strSQL = "INSERT INTO tablename(Numberfieldname1, Stringfieldname2) VALUES(" & VariableContainingNumberValueForFieldName1 & ",'" & VariableContainingStringValueForFieldName2 & "')"



Good Luck

Edit: to see correctly toggle to plain text
Last edited by vb5prgrmr; 20 Days Ago at 10:11 am.
If anyone has helped you solve your problem, please mark your thread as solved.

Thanks
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC