Vba Condtion Error

faizulhu

Registered User.
Local time
Today, 11:49
Joined
Oct 30, 2006
Messages
15
I am trying to create a code that will allow data to be saved if the condition of the 2 fields is met. The 2 fields are "Copies" and "Borrow".

The thing I want to do is as follows:

If borrow<3 and return>1 then allow the record to be saved and subtract 1 from the value of return and add one to the value of borrow.

If borrow is not <3 then show msgbox1 and delete the last record of the table.

If return is not >1 then show msgbox2 and delete the last record of the table.

If both of the condition are negetive, then show msgbox3.

I wrote the folllowing code:
Private Sub Command22_Click()
On Error GoTo Err_Command22_Click

If Copies.Value > "1" And Borrow.Value < "3" Then
DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
Copies.Value = Copies.Value - 1
Borrow.Value = Borrow.Value + 1
Else
If Copies.Value = 1 Then
If MsgBox("There are no copies of this book in library", vbInformation + vbOKOnly, "Error") = vbOK Then
DoCmd.GoToRecord , , acLast
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
Exit Sub
End If
If Borrow.Value = 3 Then
If MsgBox("The Borrower has reached his Borrowing Limit", vbInformation + vbOKOnly, "Error") = vbOK Then
DoCmd.GoToRecord , , acLast
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
Exit Sub
End If
If Borrow.Value = 3 And Copies.Value = 1 Then
If MsgBox("The Borrower has reached his Borrowing Limit And There are no copies of this book in library", vbInformation + vbOKOnly, "Error") = vbOK Then
DoCmd.GoToRecord , , acLast
DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
Exit Sub
End If
End If
End If
End If
End If
Exit_Command22_Click:
Exit Sub

Err_Command22_Click:
MsgBox Err.Description
Resume Exit_Command22_Click

End Sub



The problem is that even if the borrow and return value does not match the condition, it allows the record to be saved but the value of the 2 fields are not updated. But i wanted it to show the message boxes.

I am a beginner in Access so please elaborate the solution of my problem.
 
Um, maybe because you are updating the fileds AFTER you save the record?
 
and you don't put numbers in quotes "" - only text goes in quotes

try using the "ElseIf" it'll cut down on the code.

Col
 

Users who are viewing this thread

Back
Top Bottom