Results 1 to 5 of 5
  1. #1
    akika is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2018
    Posts
    27

    Error 2105 - when opening form via button


    hi,
    Ive added below code in form load for 'FormEntry'.
    however, the issue that am getting is that i have another continuous form 'FormSearchBy' which contains a button.
    This button 'opens selected record', open the formEntry(condition is ID = ID).

    But this i have below code in formEntry.. I'm getting error 2105, you cannot go to the specified record.

    Private Sub Form_Load()
    DoCmd.GoToRecord , , acNewRec
    End Sub

    pls help.

  2. #2
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    You can't specify the ID of a new record if that is the primary key.

    Your code is saying
    Open the form on "This ID"

    Then your form code is saying
    Open on a new record

    You can't do both.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    akika is offline Novice
    Windows 10 Access 2016
    Join Date
    Aug 2018
    Posts
    27
    ID is indeed the primary key.. wht would u suggest?
    is it possible via the macro or any code to bypass this error?

    in the Microsoft Visual Basic dialog, when click End button instead of debug.. the form is opened and record displayed.
    pls advise.

  4. #4
    Minty is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,001
    What are you trying to achieve?
    If it's to simply open the form on the record with the ID then remove the on load code from the form.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #5
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,016
    If you want to open the secondary Form to a given Record (if it exists in the secondary Form) but open it to a New Record (if it doesn't exist in the secondary Form) and assign it the ID of the primary Form's Record...here's some boilerplate code I did ages ago for a poster to do just that:

    In the Primary Form:

    Code:
    Private Sub Go2SecondaryForm_Click()
    
    DoCmd.RunCommand acCmdSaveRecord
    
     If Nz(Me.RecordID,"") <> "" Then
      DoCmd.OpenForm "Secondary Form", , , , , , Me.RecordID
     Else
      MsgBox "A RecordID Must Be Entered First!"
     End If
    
    End Sub


    In the Secondary Form:

    Code:
    Private Sub Form_Load()
    
    Dim rst As Recordset
    
    If Nz(Me.OpenArgs,"") <> "" Then
    
     Set rst = Me.RecordsetClone
     
     rst.FindFirst "[SecondaryRecordID] = " & Me.OpenArgs 
     
       If Not rst.NoMatch Then
          Me.Bookmark = rst.Bookmark
       Else
        DoCmd.GoToRecord , , acNewRec
        Me.SecondaryRecordID = Me.OpenArgs
       End If
    
    rst.Close
    
    Set rst = Nothing
    
    End If
    
    End Sub


    The above code assumes that RecordID is Numeric. If it is actually defined Text, replace the line

    rst.FindFirst "[SecondaryRecordID] = " & Me.OpenArgs

    with

    rst.FindFirst "[SecondaryRecordID] = '" & Me.OpenArgs & "'"

    You'll also need to replace Go2SecondaryForm with the actual name of your Command Button and SecondaryForm.

    Also note that, as already suggested, the SecondaryRecordID, which acts as a Foreign Key, in this scenario, cannot be an AutoNumber Field, but must be defined as a Datatype that matches the Datatype of the RecordID, from the primary Form.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

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

Similar Threads

  1. Replies: 7
    Last Post: 09-13-2017, 06:36 AM
  2. Error 2105 all of a sudden
    By TaliaKlein in forum Forms
    Replies: 7
    Last Post: 11-09-2015, 10:47 AM
  3. Replies: 10
    Last Post: 10-22-2013, 07:35 AM
  4. Replies: 5
    Last Post: 08-22-2012, 04:27 AM
  5. Replies: 3
    Last Post: 07-13-2011, 02:04 PM

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