Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2004
    Location
    Wisbech, England
    Posts
    3

    Unanswered: Another Run-Time Error 2501

    Hi all

    Have one of those runtime errors that I can't figure out.

    I am trying to open a form from another. This is based on the Northwind DB. I got it to work OK in the Northwind DB, but doesn't when I change to suit mine.

    I have two forms: frmTrainers and frmTrainerDetails and the idea is that when the users types in the TrainerID, the frmTrainerDetails should open. After typing in the ID is when I get the Run-time error.

    This is the code:

    Function OpenFormWithInput()
    Dim Msg As String
    Dim Title As String

    Dim Answer As String

    Msg = "Enter a Trainer ID"
    Title = "Open Trainer Details Form"
    Answer = InputBox(Msg, Title)
    If Answer <> "" Then
    DoCmd.OpenForm "frmTrainers", , , "[TrainerID]='" & Answer & "' "

    Else
    DoCmd.OpenForm "frmTrainers"
    End If
    End Function


    When running the de-bugging facility, the error is ponted at : DoCmd.OpenForm "frmTrainers", , , "[TrainerID]='" & Answer & "' "


    Can anyone give me a hand to sort this out. Spent hour trying to figure it out!

    TIA

    Ken

  2. #2
    Join Date
    Feb 2004
    Location
    Canada
    Posts
    133

    Re: Another Run-Time Error 2501

    Isn't frmTrainers already open? And aren't you trying to open frmTrainerDetails? Your code is trying to open frmTrainers.
    Last edited by bmacr; 03-27-04 at 15:24.

  3. #3
    Join Date
    Mar 2004
    Location
    Wisbech, England
    Posts
    3
    Hi

    Yes. frmTrainers is the open page. I have changed DoCmd.OpenForm "frmTrainers", , , "[TrainerID]='" & Answer & "' "
    to DoCmd.OpenForm "frmTrainerDetails", , , "[TrainerID]='" & Answer & "' " but I still get the same error.

    Can't figure it out

    Ken

  4. #4
    Join Date
    Nov 2003
    Posts
    1,487
    Without knowing what the actual error is, I have to assume (by looking at your code) that perhaps you are getting a Type Mismatch error (???). Just quessing here but if [TrainerID] is a number field in your table then you should Dim Answer as to what the table field is.

    Try:

    DoCmd.OpenForm "frmTrainers", , , "[TrainerID] = " & CLng(Val(Answer))



Posting Permissions

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