Results 1 to 4 of 4
  1. #1
    cptNemo is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Sep 2012
    Posts
    10

    Code for button to open new form passing value

    Hello,



    I have a 8 forms referring to 8 tables. Tables are all related by the ID field (which is also the primary key) one-to-one to the ID fIeld of the first table.

    At the end of each form I need to code the button to open the next form following this rules:

    1) get the value of field ID of form 1;
    2) open a new form;
    3) look for value of ID from form 1 in ID in table 2:
    If value exists load corresponding record in form 2
    If value does not exist open new record in table 2 and pass value to field ID of form 2.

    I am having some problems writing it... Any idea?

    Thanks.

  2. #2
    cptNemo is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Sep 2012
    Posts
    10
    I came out with this code. Of course is not working, all sorts of logical/syntax mistakes...

    Private Sub Command61_Click()

    Dim localID As Integer
    localID = Forms!SectionA.ID

    If (DLookup("[ID]", "Section B", "[ID]" = localID) = Null) Then
    DoCmd.OpenForm "SectionB"
    DoCmd.GoToRecord acDataForm, "SectionB", acNewRec
    Else
    DoCmd.OpenForm "SectionB", , , "ID = localID"


    End If


    End Sub

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    For starters, nothing is "= Null". Try the IsNull() function.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    cptNemo is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Sep 2012
    Posts
    10
    Solved! See below

    If (DLookup("ID", "Section B", "[ID] = '" & Me!ID & "'") = Null) Then
    DoCmd.OpenForm "SectionB", acNormal, "", "", acAdd, acNormal
    Forms![SectionB]![ID] = Me.[ID]

    Else
    DoCmd.OpenForm "SectionB", , , "ID = '" & Me!ID & "'"
    End If

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

Similar Threads

  1. Replies: 3
    Last Post: 05-09-2012, 04:04 PM
  2. Replies: 1
    Last Post: 05-03-2012, 02:25 PM
  3. VB Code to open a form?
    By HeadGasket in forum Access
    Replies: 1
    Last Post: 01-24-2012, 08:26 PM
  4. cmd button to open form
    By stephaniehpcswf in forum Access
    Replies: 1
    Last Post: 02-23-2011, 04:46 PM
  5. Replies: 2
    Last Post: 02-26-2010, 08:14 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