Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2012
    Posts
    3

    Unanswered: Missing something very basic?

    I have a command button on a (Contacts) form, to open a second form and apply the ContactID of the current record to that form. It seems okay if there are no existing records already assigned to that particular ContactID, as it opens to a new record in the second form, with the ContactID already populated. However, when a contact already has an associated record in the second form, it opens to that record, instead of a new record. What am I missing? I hasten to add I am completely new to databases and coding etc., so I'm learning as I go.

    My code is as follows:

    'Open the enquiry form and enter data for this person.

    If Not IsNull(Me.ContactID) Then
    DoCmd.OpenForm "frmEnquiry", , , , , , Me.ContactID
    End If
    DoCmd.OpenForm "frmEnquiry", , , "ContactID=" & Me.ContactID

    Is there a way to get the second form to always open to a new record for the current contact, even if a contact already has other 'contact events' existing in the Enquiry table?

    Also, if a user tries to open the second form without first entering contact details, is there a way to cancel the action and advise that they must be on an existing record for this button to operate?

    Hope this makes sense!

    Many thanks.

  2. #2
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Something like this?

    In the Primary Form:
    Code:
    Private Sub Go2SecondaryForm_Click()
    
     If Nz(Me.ContactID,"") <> "" Then
      DoCmd.OpenForm "frmEnquiry", , , , , , Me.ContactID
     Else
      MsgBox "A ContactID Must Be Entered First!"
     End If
    
    End Sub


    In frmEnquiry:

    Code:
    Private Sub Form_Load()
    
        DoCmd.GoToRecord , , acNewRec
        
        If Nz(Me.OpenArgs,"") <> "" Then
          Me.ContactID = Me.OpenArgs
        End If

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    Join Date
    Sep 2012
    Posts
    3
    Perfect. Thank you!

  4. #4
    Join Date
    Sep 2012
    Posts
    3
    Oops - now the form also opens to a new record from my search form (rather than to the selected record in the search form).

    NEVER MIND - momentary brain fade!

    Thank you again - you've solved a problem, and caused me to actually think a little! Suffering from beginners frustration at the moment!
    Last edited by newjfn; 08-23-13 at 09:40.

  5. #5
    Join Date
    Jun 2005
    Location
    Richmond, Virginia USA
    Posts
    2,763
    Provided Answers: 19
    Glad we could help!And don't worry about the beginner's frustration; that's normal! Programming language, like any language, takes a bit of getting used to!

    Linq ;0)>
    Hope this helps!

    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Posting Permissions

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