Results 1 to 5 of 5
  1. #1
    3 Star Lounger
    Join Date
    Nov 2002
    Location
    Belfast, Ireland
    Posts
    339
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Hello

    I have a simple bit of code that I'd like to get working. We have a Purchase Order Database, and I want to ensure that a User enters a Valid password to authorize a Purchase Order.
    If the username matches the code, then the "Save & Close" button appears. If it doesn't match, then the button stays hidden, a msg box appears, and the Text Box should be reset to blank (this is important, as Access shows those with no Codes as Unauthorized.

    The Code I've got is as follows:

    Code:
    If cboAB = 7 And AuthCode.Text = "xxxx" Then
    cmdSave.Visible = True
    Else: cmdSave.Visible = False
    MsgBox ("That Authorization Code was incorrect")
    AuthCode.SetFocus
    AuthCode.Text = ""
    End If
    However, when I test the code with an incorrect password, the Else Condition kicks in and Access thows up the following errors
    2115. The macro or function set to the BeforeUpdate or ValidationRule property for this field is preventing Access from saving the data in the Field.

    But I have no Validation Rule or BeforeUpdate Event?

    Can anyone see what I'm doing wrong?

    Many thanks in advance.

    Brian

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Where did you put the code that you posted?

  3. #3
    New Lounger
    Join Date
    Dec 2009
    Location
    Phoenix, Arizona, USA
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It looks like you have a colon after your else. This would interpret the "Else" as a label which is used for error trapping. Therefore your code just executes the statements below the label as if your if statement if one block of code. - Remove the colon.

    microboss

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Quote Originally Posted by Henry Jenkins View Post
    It looks like you have a colon after your else. This would interpret the "Else" as a label which is used for error trapping.
    In this case, the colon is used to place multiple instructions on a single line. Although this is not recommended, it is valid VBA. So I don't think it is the cause of Brian's problem.

  5. #5
    5 Star Lounger AndrewKKWalker's Avatar
    Join Date
    Apr 2001
    Location
    Cambridge, UK
    Posts
    1,020
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Code:
    If cboAB = 7 And AuthCode.Text = "xxxx" Then
    	cmdSave.Visible = True
    Else
    	cmdSave.Visible = False
    	MsgBox ("That Authorization Code was incorrect")
    	AuthCode.SetFocus
    	AuthCode=NULL
    End If
    I have seen this code appear when a module gets corruption,
    and a compact and repair fixes it.
    BUT.. It looks like it might be on the Before Update event of AuthCode,
    in which case attempting to Update Authcode during its Before Update Event would probably cause this.

    However, I am only guessing.
    Andrew

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •