Results 1 to 10 of 10
  1. #1
    ShaneO is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2011
    Posts
    5

    Thumbs down Error 2501: I can open a form in 'Add' mode, but not 'ReadOnly'

    Hi,

    I'm new to the forums, there seems to be a nice helpful community here!

    My question is in regards to opening a form in ReadOnly mode. I've been working on this for hours; hopefully there's an answer.

    Basically I need to open the form while linking a hidden field to the form. This works fine in 'acFormAdd' mode, but does not work in 'acFormReadOnly' mode.



    My code to open the form:

    Code:
    Private Sub cmdOpen_Click()
    On Error GoTo addJump
    Call openForm("frmProgress", "[ProjectID]=" & "'" & _
                    Form_frmProjectScreen![ProjectID] & "'", "Add")
    Exit Sub
    addJump:
        Call addJumpRun
        
    End Sub
    Code:
    Sub openForm(stDocName As String, Optional stLinkCriteria As String, _
                Optional stType As String) ' Add, Read
                          
        Dim tmpStType As String
        
        Select Case stType
        
        Case "Add"
        
            DoCmd.openForm stDocName, , , stLinkCriteria, acFormAdd
            
        Case "Read"
        
            DoCmd.openForm stDocName, , , stLinkCriteria, acFormReadOnly
            
        Case Else
        
            DoCmd.openForm stDocName, , , stLinkCriteria
            
        End Select
        
    End Sub

    As you can see, the link criteria carries over the [ProjectID], which is a hidden field on both forms. If I change "Add" to "Read" when calling the OpenForm procedure, access gives me a 2501 runtime error saying the form can't open.

    The query I use on the other form (that uses the [ProjectID]) looks like:

    Code:
    SELECT TOP 1 tblPhases.PhaseName, tblUpdates.UpdateDate, tblUpdates.ProjectID, tblUpdates.TopicID, tblUpdates.PhaseID FROM tblPhases INNER JOIN tblUpdates ON tblPhases.PhaseID=tblUpdates.PhaseID GROUP BY tblPhases.PhaseName, tblUpdates.UpdateDate, tblUpdates.ProjectID, tblUpdates.TopicID, tblUpdates.PhaseID HAVING (((tblUpdates.ProjectID)=Forms!frmProjectScreen!ProjectID) And ((tblUpdates.TopicID)=6)) ORDER BY tblUpdates.UpdateDate DESC;
    I'm thinking it might be a form properties glitch or maybe SQL statement is somehow messing it up? I don't know. I know my vba calls for "Read" and "Add" are correct because I use the same call for multiple other related forms.

    The situation would make more sense if both 'Add' and 'ReadOnly' didn't work.. but 'Add' works perfectly.



    Thanks for your help

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Everything appears to be okay so I would try *importing* everything into a fresh new db and see if the problem follows: http://www.btabdevelopment.com/ts/impnew

  3. #3
    ShaneO is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2011
    Posts
    5
    Hi RuralGuy thanks for the response.

    I imported everything into a blank database and the problem persists.


    I should add that I have tried error handling; if error 2501 were to be detected, skip all error messages and continue to the next line.
    When I tried this the form would not open.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    The error indicates Access does not like one of the arguments. Try a MsgBox on the stLinkCriteria just before using it and see what you have.

  5. #5
    ShaneO is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2011
    Posts
    5
    stLinkCriteria =

    [ProjectID]='19'



    See attachment for the other variable watches.

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Is [ProjectID] a text or numeric field?

  7. #7
    ShaneO is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2011
    Posts
    5
    Numeric (AutoNumber)

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You are treating it as a Text field by surrounding it with single quotes. It should be:
    [ProjectID]=19

  9. #9
    ShaneO is offline Novice
    Windows XP Access 2003
    Join Date
    Apr 2011
    Posts
    5
    That fixed it!

    I really appretiate your help.

    I still find it odd how it did work when I used "add" rather than "readonly".


    Thanks a lot again for your help, it probably saved me several hours of trail and error.

    Regards,

    Shane

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Add turns on DataEntry and does not care about filters (WhereCondition). If you are good to go then go ahead and use the Thread Tools and mark this thread as Solved.

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

Similar Threads

  1. Replies: 15
    Last Post: 07-26-2012, 02:06 PM
  2. Replies: 4
    Last Post: 01-14-2011, 10:37 AM
  3. Access copy/paste error in Shared mode
    By somm in forum Access
    Replies: 6
    Last Post: 12-16-2010, 08:59 AM
  4. more than one table error in report mode
    By jonesy29847 in forum Reports
    Replies: 3
    Last Post: 07-19-2010, 01:11 PM
  5. Open Form in Add Mode
    By Boreal2009 in forum Programming
    Replies: 2
    Last Post: 10-23-2009, 10:53 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