With the coding below i am trying to input a cylinder number into the tblupdate table, when the cylinder number inputed matches the cylinder number within the tblupdate table the cylinder status is set to returned, however if the cylinder number inputed does not match the cylinder number inputed then a new record should be added to the table with the cylinder number and status of the cylinder. However when running this code it works when the cylinder number matches the cylinder number in the table that record is edited in the table, but when the cylinder number does not match, i get the follwong error "run-time error 3021, no current record". How do i overcome this??
My Code:
Private Sub Command22_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim StrSQl As String
Dim String3 As Integer
Dim Stringy4 As Date
Set db = CurrentDb
Stringy3 = InputBox("Are There Any Returns", "Please Scan/Enter Cylinder Serial Number")
Stringy4 = InputBox("Please Enter the Cylinder Return Date")
Set rs = db.OpenRecordset("SELECT * From tbl_Delupdate Where [Cylinder Number] = '" & Stringy3 & "'")
If rs![Cylinder Number] = Stringy3 Then
rs.Edit
rs![R Status] = "Returned"
rs![Date of R Status] = Stringy4
rs.Update
If Stringy3 = rs![Cylinder Number] Then
rs.AddNew
rs![Cylinder Number] = Stringy3
rs!Status = "Returned"
rs!CustNo = Me!CustNo
rs.Update
End If
End If
rs.Close
db.Close
End Sub
My Code:
Private Sub Command22_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim StrSQl As String
Dim String3 As Integer
Dim Stringy4 As Date
Set db = CurrentDb
Stringy3 = InputBox("Are There Any Returns", "Please Scan/Enter Cylinder Serial Number")
Stringy4 = InputBox("Please Enter the Cylinder Return Date")
Set rs = db.OpenRecordset("SELECT * From tbl_Delupdate Where [Cylinder Number] = '" & Stringy3 & "'")
If rs![Cylinder Number] = Stringy3 Then
rs.Edit
rs![R Status] = "Returned"
rs![Date of R Status] = Stringy4
rs.Update
If Stringy3 = rs![Cylinder Number] Then
rs.AddNew
rs![Cylinder Number] = Stringy3
rs!Status = "Returned"
rs!CustNo = Me!CustNo
rs.Update
End If
End If
rs.Close
db.Close
End Sub