Results 1 to 5 of 5
  1. #1
    4 Star Lounger
    Join Date
    Feb 2002
    Posts
    537
    Thanks
    0
    Thanked 0 Times in 0 Posts

    forbid selecting a product in the subform (Access 2000)

    I have a main form called main and subform called Subform. In my database it is possible to select a product in the subform without having selected a customer from the main form. true, i receive an error but i want programatically to return the user to the inititial position, with the message
    strMsg = "You can't add or edit a product since you have not selected a Customer"
    What is the shortest posible method to write this code? I suppose something with Customer = "" or something like that,but it doesnt work with me.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: forbid selecting a product in the subform (Access 2000)

    You can add code to the OnError event of the subform to intercept this error. I presume that your error message is something like "Index or primary key can't contain a Null value". This is error # 3058.

    Private Sub Form_Error(DataErr As Integer, Response As Integer)
    If DataErr = 3058 Then
    MsgBox "You can't add or edit a product since you have not selected a customer!", vbExclamation
    Undo
    Response = acDataErrContinue
    End If
    End Sub

  3. #3
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: forbid selecting a product in the subform (Access 2000)

    You said that "...it is possible to select a product in the subform without having selected a customer from the main form. " Do you really WANT to allow that, or are you just trying to get around the error created when it happens? To prevent it, you can easily add code to the OnEnter event of your subform control on the mainform that locks it when you are on a new record.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  4. #4
    4 Star Lounger
    Join Date
    Feb 2002
    Posts
    537
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: forbid selecting a product in the subform (Access 2000)

    Dear Hans,

    Thank you very much for your reply.Of course your code works, could you please help me further?
    Together with the message a dialog box appears with the message, having the option "debug".
    Can i avoid this option, i just want that the code returns me to the orginal positin without the dialog window for Debug

    Best regards

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: forbid selecting a product in the subform (Access 2000)

    Do you mean that the Debug option is displayed in the message box with the text "You can't add or edit a product since you have not selected a customer!", or in a separate dialog box?

    If the latter is the case, there seems to be an error somewhere. To find out what is happening:
    <UL><LI>Write down the exact wording of the dialog box with the debug option.
    <LI>Select the debug option; a code window should open with the offending line highlighted in yellow. Note the location.[/list]If you post the wording of the dialog box and the code (at least the offending line, but preferably a bit more, with an indication on which line the error occurred), I and/or others can try to find out what is happening.

Posting Permissions

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