Link to home
Start Free TrialLog in
Avatar of alex_wareing
alex_wareing

asked on

Simple Update code

I'm having trouble with some update code, heres my code:

------------------------------------------------
'Open the connection the backend DB
DIM objConn
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = MM_RMbackend_STRING
objConn.Open

'Open the table where the records are to be inserted using the key passed from the form
DIM getAppt, Query1, FormKeyVar
FormKeyVar = Request.Form("AppointmentID")
Set getAppt = Server.CreateObject("ADODB.Recordset")
Query1 = "SELECT * FROM Appointments WHERE AppointmentID = " + Replace(FormKeyVar, "'", "''") + ""
getAppt.Open Query1, objConn, , adLockOptimistic, adCmdTable
Const AdOpenDynamic = 1
Const adCmdText = 1
Const adLockOptimistic = 3

'check if last app within 90 days of new app
dim lastAppDate, thisAppDate, statBook

If getOtherApps.EOF And getOtherApps.BOF Then
      lastAppDate = #01/01/01#
      thisAppDate = (getAppt.Fields.Item("AppointmentDate").Value)
else
      lastAppDate = #01/05/05#
      thisAppDate = (getAppt.Fields.Item("AppointmentDate").Value)
end if

If DateDiff("d", lastAppDate, thisAppDate) >= 90 Then
      
      'Update the selected record
      getAppt("AppointmentRep") = Request.Form("RepID")
      getAppt("AppointmentSubject") = Request.Form("AppointmentSubject")
      getAppt("Booked") = 1
      getAppt.Update

end if
--------------------

When i run the page i get this error:

Microsoft OLE DB Provider for ODBC Drivers error '80004005'

Query-based update failed because the row to update could not be found.

/repeatprescribe/regenthouse/repbook2.asp, line 94 [this is the getAppt.Update line]

When i run the SQL query Query1  it returns the record. whats wring with my code.
Avatar of xiong8086
xiong8086

change this :
If getOtherApps.EOF And getOtherApps.BOF Then
     lastAppDate = #01/01/01#
     thisAppDate = (getAppt.Fields.Item("AppointmentDate").Value)
else
     lastAppDate = #01/05/05#
     thisAppDate = (getAppt.Fields.Item("AppointmentDate").Value)
end if

To
If getOtherApps.EOF OR getOtherApps.BOF Then
     lastAppDate = #01/01/01#
     thisAppDate = (getAppt.Fields.Item("AppointmentDate").Value)
else
     lastAppDate = #01/05/05#
     thisAppDate = (getAppt.Fields.Item("AppointmentDate").Value)
end if

why not use a update statement directly?

best regards,
Xiong
ASKER CERTIFIED SOLUTION
Avatar of nurbek
nurbek

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you are assinging

Const AdOpenDynamic = 1
Const adCmdText = 1
Const adLockOptimistic = 3

after opening the recordset
Avatar of alex_wareing

ASKER

Works great, is there any chance you could explain this problem a little more
I usually use
getAppt.Open Query1, objConn, 3, 3  ------- for inserting, updating, deleting

getAppt.Open Query1, objConn, 1, 1 -------  i open it just for reading

3,3 or 1,1, defines the recordset object for read/write and  movenext/moveprev/requery etc..

hope this makes a sense :)

regards,
Nurbek