Results 1 to 5 of 5
  1. #1
    Girraffa is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    32

    Question Opening form in acPreview Run-time error '2499'

    I have been building a database for a small animal care facility. I have a report that summarizes information about an animal including basic details of exams, procedures and reports that have been associated with that animal--these are all subforms. Each record in a subform has a button that allows the user to open the full record (form) which I was hoping to do in acPreview mode so they can't accidentially change stuff in the record. The forms themselves are defaulted to open on a new record for data entry purposes, so I am using gotorecord to make sure they open on the record of interest. The code worked fine when I was having the forms open in acNormal, however when I switched to acPreview I get "run-time error '2499'" which says the method can't be applied to an object in design mode, which the forms are not. It still opens the form in preview mode though! As long as you click "end" on the error message you can go ahead and view the record. What am I doing wrong? Do I just need to make reports for these forms and have those open instead? I can certainly do that but am also curious what's going wrong here for the sake of better understanding.



    Code in the button:

    Private Sub cmdViewFull_Click()
    Dim sWhich As String
    sWhich = "[ExamAutoID]= " & Me.txtExamAutoID
    DoCmd.OpenForm "ExamForm", acPreview, , sWhich
    DoCmd.GoToRecord acDataForm, "ExamForm", acGoTo, 1
    End Sub

    If there's another thread about this I apologize, I looked and couldn't find one. Thank you very much for any guidance!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Can't use GoToRecord with preview.

    Preview is hard to look at anyway. Use code that locks the form in normal view.

    DoCmd.OpenForm "ExamForm", , , "[ExamAutoID]= " & Me.txtExamAutoID, , acFormReadOnly
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Girraffa is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    32
    Thank you for your reply! That works to open the form but opens it on a new record and one is still able to edit the target record which I want to avoid in this instance. Also I have the forms set in their on open event to open on a new record for data entry purposes:

    Private Sub Form_Open(Cancel As Integer)
    'open form on a new record
    DoCmd.GoToRecord , , acNewRec
    End Sub

    and when I use your code it opens the correct record but opens up on a new record after that so the user would have to use navigation buttons to go back to the target record. Is there anything I can add to open on the target record itself?
    Is this something I should start a new thread about?
    Thanks again!

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    In my test the form does not have new record row. No code in the Open event. So tried your code in the Open event and get an error message "You cannot go to specified record.".

    Pass a value to form with OpenArgs.

    Docmd.OpenForm "ExamForm", , , "[ExamAutoID]= " & Me.txtExamAutoID, acFormReadOnly, , "ViewOnly"

    Then test for that OpenArgs string in the Open Event

    If Me.OpenArgs <> "ViewOnly" Then DoCmd.GoToRecord , , acNewRec

    Or don't use OpenArgs and instead:

    If Me.AllowAdditions Then DoCmd.GoToRecord , , acNewRec
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Girraffa is offline Advanced Beginner
    Windows 10 Access 2016
    Join Date
    Sep 2017
    Posts
    32
    Perfect thank you very much! I used the OpenArgs method. I keep forgetting about OpenArgs as an option!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Error 2770 when opening a form
    By Abacus1234 in forum Forms
    Replies: 5
    Last Post: 08-27-2016, 01:21 PM
  2. Replies: 10
    Last Post: 10-22-2013, 07:35 AM
  3. Weird Error on opening a form
    By RayMilhon in forum Forms
    Replies: 1
    Last Post: 01-10-2012, 05:44 PM
  4. Replies: 3
    Last Post: 07-13-2011, 02:04 PM
  5. Error In Opening Form
    By cwwaicw311 in forum Forms
    Replies: 1
    Last Post: 03-10-2010, 09:18 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums