CheckResNo()=True... Validation Rule Error??

nemodied

New member
Local time
Today, 06:05
Joined
Nov 8, 2008
Messages
4
Hey guys, I have an error in my Validation Rule Property... I get this error everytime I enter the Reservation Number (autonumber) into the field, to grab the Customer ID.

"The macro or function set to the beforeupdate or validationrule property for this field is preventing access from saving the data in the field"

I have nothing the the BeforeUpdate for this field, the validation rules is:
CheckResNo()=True

I only have 11 Reservations in the table... If I put "12" into the ResNoField it will say "Reservation Number Not Found" but 11 brings up the error above.

Code:
Function CheckResNo() As Boolean
    Dim db As ADODB.Connection
    Dim rs As ADODB.Recordset
    Dim RNO As Integer
    Dim RetValue As Boolean
    RNO = Forms("Reservation")!ResNoField
    RetValue = False
    Set db = CurrentProject.Connection
    Set rs = New ADODB.Recordset
    rs.Open "Select * From Customer Inner Join Reservation on Customer.CustomerID=Reservation.CustomerID Where Reservation.ResNo=" & RNO, db
    If Not rs.EOF Then
        Call DataFill3(rs)
        RetValue = True
    Cancel = vbCancel
    Forms("Reservation")!ResNoField.Undo
    End If
    rs.Close
    db.Close
    Set rs = Nothing
    Set db = Nothing
    CheckResNo = RetValue
End Function
DataFill3:
Code:
Sub DataFill3(rs As ADODB.Recordset)
  Dim fs As FileSystemObject
  Set fs = New FileSystemObject
  Forms("Reservation")!Rents.Enabled = True
  Forms("Reservation")!NewRadio.Enabled = True
  Forms("Reservation")!NewRadio.Value = 2
  Forms("Reservation")!CustIDField.Enabled = True
  Forms("Reservation")!SearchButt.Enabled = True
  Forms("Reservation")!ResNoField = rs!ResNo
  Forms("Reservation")!CustIDField = rs!CustomerID
  Forms("Reservation")!FirstNameField = rs!FirstName
  Forms("Reservation")!LastNameField = rs!Lastname
  Forms("Reservation")!TelephoneField = rs!TelNo
  Forms("Reservation")!StreetField = rs!Street
  Forms("Reservation")!CityField = rs!City
  Forms("Reservation")!ZipField = rs!Zip
  Forms("Reservation")!StateField = rs!State
  Forms("Reservation")!EmailField = rs!Email
  Forms("Reservation")!PicIDField = rs!PicID
  If fs.FileExists(rs!PicID) Then
    Forms("Reservation")!PicID.Picture = rs!PicID
   Else
    Forms("Reservation")!PicID.Picture = "c:\default.jpg"
  End If
End Sub
Thanks for the help guys!:confused::)
 
Last edited:
You have not stated which field has the validation rule applied to it. If infact the validation rule is set at table level. Also what version of Access you are using.

I am always tempted to place any validation on forms as opposed to tables especially if they have dependancies, such as open forms etc.

Your Datafill3 relies on form Resevations being opened it does not check to see if the form is loaded. You may need to look at this point.
 

Users who are viewing this thread

Back
Top Bottom