How to open form on specific record?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • reginaldmerritt
    New Member
    • Nov 2006
    • 201

    How to open form on specific record?

    Hi,

    I'm using the following code to open a form on a specific record. I have a form displaying records in a list which then allows users to click onto the record to open it up in a new form in a single view.

    Code:
    DoCmd.OpenForm "FRMBookingDetails", , "[BookingID] = " & Me.BookingID
    The form opens only on the first record only and never the chosen record. Sometimes it opens the form on a new record.

    I'm guessing this has something to do with filtering but not sure what i should be checking for.

    Thanks.
  • munkee
    Contributor
    • Feb 2010
    • 374

    #2
    I would be checking to ensure the form you are opening up has the field [BookingID] somewhere within its record.

    Other than that it could be an issue with your form properties set wrong usually Allow Filter = false etc

    Comment

    • reginaldmerritt
      New Member
      • Nov 2006
      • 201

      #3
      Thanks munkee.

      That was my first thought. But filter setting are set to true and i have the PK BookingID on the form.

      I changed the code to the following and it seems to be working again now, not sure why.

      Code:
      DoCmd.OpenForm "FRMBookingDetails", acNormal, , "[BookingID] = " & Me.BookingID

      Comment

      • munkee
        Contributor
        • Feb 2010
        • 374

        #4
        Weird. I wouldnt have expected adding the acnormal to change anything unless you have some properties set up within you form to only open in design view :| which once again I wouldnt expect.

        Comment

        • TheSmileyCoder
          Recognized Expert Moderator Top Contributor
          • Dec 2009
          • 2322

          #5
          The acNormal is the default value, so I doubt that the change there is what fixed the problem.

          I have noticed on occasion that if I have the form open in design view, and then switch to normal view, that I do not get the same behavior as if I had closed the form, and then reopened it.

          Comment

          • reginaldmerritt
            New Member
            • Nov 2006
            • 201

            #6
            That's a good point SmileyCoder. I've just noticed the same thing. Even if you make sure you save the changes sometimes there can be unexpected events if the form is not closed and then reopened.

            I've only noticed this with DoCmd.OpenForm, but perhaps this effects other functions.

            When ever i get any strange things happening i'm going to try this from now on.

            Comment

            • Lysander
              Recognized Expert Contributor
              • Apr 2007
              • 344

              #7
              I think you are missing a ' in your first example

              You say
              Code:
              DoCmd.OpenForm "FRMBookingDetails", , "[BookingID] = " & Me.BookingID
              Should it not be
              Code:
              DoCmd.OpenForm "FRMBookingDetails", , ,"[BookingID] = " & Me.BookingID

              Comment

              • TheSmileyCoder
                Recognized Expert Moderator Top Contributor
                • Dec 2009
                • 2322

                #8
                I think Lysander has a good point, exept that he meant to type , and not '. In your second example where you included the acNormal, you had the correct amount of [,].

                Comment

                • reginaldmerritt
                  New Member
                  • Nov 2006
                  • 201

                  #9
                  Sorry should have copied and pasted instead of writing it out. I do have the correct amount of commas in my code, but well spotted. Thanks SmileyCoder

                  Comment

                  Working...