Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2012
    Posts
    4

    Unanswered: Opening a form on a selected record

    Good morning everyone. I am brand new to all of this -- I haven't even played with programming in more than 20 years. Anyhow, if y'all can help me out, I would appreciate it. I have created a form that upon opening asks the user to select a campus. They then need click the "OK" button. Upon doing so, a new form ("Campus_Select") should open up on the particular record selected. At this point, upon clicking on the "OK" button, the user gets the following message:
    Run-time error '2501:'
    The Open-Form action was canceled.

    If I then select the "Debug" key on the pop-up window, I am taken to the VBA screen, where the following is highlighted:

    DoCmd.OpenForm "Campus_Input", acNormal, , , acFormEdit, acWindowNormal, SelectedNameofSchool

    When the cursor is over "SelectedNameofSchool" I can see that the selected school is correct, so It seems that at least the school is being selected.

    Here is my code:

    Option Explicit
    Private Sub Command1_Click()

    Dim SelectedNameofSchool As String

    SelectedNameofSchool = "[Name of School] = '" & Me![School_Choice] & "'"""

    DoCmd.OpenForm "Campus_Input", acNormal, , , acFormEdit, acWindowNormal, SelectedNameofSchool

    End Sub

    The code on my "Campus_Input" form is as follows:

    Option Compare Database

    Private Sub Form_Open(Cancel As String)
    If Not IsNull(Me.OpenArgs) Then
    Dim lngID As Long
    Dim rs As Object

    Set rs = Me.Recordset.Clone
    lngID = Val(Me.OpenArgs)
    rs.FindFirst "[Name of School] = '" & lngID
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark
    End If


    End Sub

    Been trying to figure this out for a week. Your help is appreciated.

    Aloha,

    Luis

  2. #2
    Join Date
    Mar 2009
    Location
    Dorset
    Posts
    119
    The SelectedNameofSchool variable looks like it holds a Where condition so this should go before the acFormEdit as follows:

    DoCmd.OpenForm "Campus_Input", acNormal, ,SelectedNameofSchool , acFormEdit, acWindowNormal
    Regards
    JD

    Software-Matters

  3. #3
    Join Date
    Oct 2012
    Posts
    4

    New error

    Thanks JD.

    I made that change, but I got a new error. It read:

    Run-time eror '3075':
    Syntax error in string in query expression '[Name of School] = 'Adamson, W.H.'".

    Also -- don't know if this is pertinent: When I try to open the 2nd form, I get this message:

    "The expression On Open you entered as the event property setting produced the following error: Procedure declaration does not match description of event or procedure having the same name."

    Thanks,

    Luis
    Last edited by LuisV; 10-11-12 at 14:22.

  4. #4
    Join Date
    Oct 2012
    Posts
    4

    New error removed

    Ok. I changed

    SelectedNameofSchool = "[Name of School] = '" & Me![School_Choice] & "'"""
    with:
    SelectedNameofSchool = "[Name of School] = '" & Me![School_Choice] & "'"

    and I get the original error again:

    Run-time error '2501:'
    The Open-Form action was canceled.

  5. #5
    Join Date
    Oct 2012
    Posts
    4

    Figured it out.

    Ok. Thanks for your help. I pieced a couple things together -- the problem was in the code for the 2nd window. I cleared all I had and just used a macro to close the 1st window.

    Thanks. I used info from several threads.

    Aloha!

    Luis.

  6. #6
    Join Date
    Oct 2012
    Posts
    3
    If School_Choice is combobox or check box, so why don't you replace this:
    SelectedNameofSchool = "[Name of School] = '" & Me![School_Choice] & "'"""
    with
    SelectedNameofSchool = Me![School_Choice]

Posting Permissions

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