Results 1 to 14 of 14
  1. #1
    pfarnell is offline Novice
    Windows XP Access 2010 (version 14.0)
    Join Date
    Sep 2010
    Posts
    8

    Insert Record checks table


    To keep it simple, I have a need to as I insert a numeric record into a table that the form makes a call to say go to Form1 if the number is already in the table or Form2 if the record is not in the table. I have been attepting to do this using an embedded macro based on a form event but with no joy. Any ideas ?

  2. #2
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    if dlookup("numfield","table1","numfield=" & aNumber ) = null then
    docmd.openform "form1"
    else
    docmd.openform "form2"
    end if

  3. #3
    pfarnell is offline Novice
    Windows XP Access 2010 (version 14.0)
    Join Date
    Sep 2010
    Posts
    8
    I am not quite sure I understand this, which part of this passes the number from the form ?

  4. #4
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    suppose aNumber is the object which you have the number in.

  5. #5
    pfarnell is offline Novice
    Windows XP Access 2010 (version 14.0)
    Join Date
    Sep 2010
    Posts
    8
    Can I just clarify, where do I put this code ? Sorry Access new boy.

  6. #6
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    Quote Originally Posted by pfarnell View Post
    To keep it simple, I have a need to as I insert a numeric record into a table that the form makes a call to say go to Form1 if the number is already in the table or Form2 if the record is not in the table. I have been attepting to do this using an embedded macro based on a form event but with no joy. Any ideas ?
    How did you insert a numeric record into a table ? you need to put the code before you insert a record.

  7. #7
    pfarnell is offline Novice
    Windows XP Access 2010 (version 14.0)
    Join Date
    Sep 2010
    Posts
    8
    I am putting it as an On Exit event on a field, so I barcode in the number and the barcode is set to tab. Code in code builder looks like this.

    Private Sub DelegateReferenceNo_Exit(Cancel As Integer)
    If DLookup("DelegateReferenceNo", "CheckIn", "DelegateReferenceNo = [DelegateCheckIn]![DelegateReferenceNo]") = Null Then
    DoCmd.OpenForm "GoodBadge"
    Else
    DoCmd.OpenForm "DuplicateBadge"
    End If
    End Sub

  8. #8
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    Did you get it work?
    Or more question?

  9. #9
    pfarnell is offline Novice
    Windows XP Access 2010 (version 14.0)
    Join Date
    Sep 2010
    Posts
    8
    No it did not work, seems not to want to user the form field bit.

  10. #10
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by pfarnell View Post
    No it did not work, seems not to want to user the form field bit.
    farnell,

    maybe I can issue some help here - are you scanning badges into the system's log when employees enter a corporate building perhaps?

    if so, I'm not sure why you have two tables. But at any rate, weekend gave you a domain function, which has a syntax that is relevant to your situation such that:

    Code:
    Private Sub DelegateReferenceNo_Exit(Cancel As Integer)
    
    If DLookup("DelegateReferenceNo", "CheckIn", _
    "CRITERIA HERE") Then
    DoCmd.OpenForm "GoodBadge"
    Else
    DoCmd.OpenForm "DuplicateBadge"
    End If
    End Sub
    To me, the following line of code is unclear:
    Code:
    "[DelegateReferenceNo] = [DelegateCheckIn]![DelegateReferenceNo]") = Null
    what are you trying to do with that? What is [DelegateCheckIn]!?? Is that a form reference? A table? A query?

    Just a little more tweaking and you should have it no problem.

  11. #11
    pfarnell is offline Novice
    Windows XP Access 2010 (version 14.0)
    Join Date
    Sep 2010
    Posts
    8
    Only got one table "CheckIn", "DelegateCheckIn" is a form.

  12. #12
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by weekend00 View Post
    if dlookup("numfield","table1","numfield=" & aNumber ) = null then
    docmd.openform "form1"
    else
    docmd.openform "form2"
    end if

    The problem is with "DLookup(blah) = NULL" . Nothing is equal to NULL, not even NULL. If you write

    If NULL=NULL Then
    MsgBox "True"
    Else
    MsgBox "False"
    End if


    This will *always* display FALSE.

    Try:

    IF ISNULL(Dlookup("numfield","table1","[numfield] = " & aNumber )) THEN
    DoCmd.Openform "form1"
    ELSE
    DoCmd.Openform "form2"
    END IF


    HTH
    ----
    Steve
    --------------------------------
    "Veni, Vidi, Velcro"
    (I came; I saw; I stuck around.)

  13. #13
    pfarnell is offline Novice
    Windows XP Access 2010 (version 14.0)
    Join Date
    Sep 2010
    Posts
    8
    I have the following now but it always goes to "duplicate badge" despite it not having been checked in before.

    Private Sub DelegateReferenceNo_Exit(Cancel As Integer)
    If IsNull(DLookup("DelegateReferenceNo", "CheckIn", "DelegateReferenceNo = [Forms].[BadgeProduction]![DelegateReferenceNo]")) Then
    DoCmd.OpenForm "GoodBadge"
    Else
    DoCmd.OpenForm "DuplicateBadge"
    End If
    End Sub

  14. #14
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    The Where clause is looking for "[Forms].[BadgeProduction]![DelegateReferenceNo]" in the field "DelegateReferenceNo". DLookup does not/cannot evaluate the reference to the control within the quotes.

    Try:

    If IsNull(DLookup("DelegateReferenceNo", "CheckIn", "DelegateReferenceNo = " &[Forms]![BadgeProduction].[DelegateReferenceNo])) Then


    HTH
    ----
    Steve
    --------------------------------
    "Veni, Vidi, Velcro"
    (I came; I saw; I stuck around.)

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

Similar Threads

  1. INSERT query: insert new data only
    By drh in forum Access
    Replies: 2
    Last Post: 04-04-2014, 05:31 PM
  2. Insert into table
    By Mclaren in forum Programming
    Replies: 4
    Last Post: 05-02-2010, 11:28 PM
  3. Replies: 0
    Last Post: 02-24-2010, 12:56 AM
  4. Replies: 6
    Last Post: 08-17-2009, 01:41 AM
  5. Insert Query output into a table
    By ammu_sridhar in forum Programming
    Replies: 1
    Last Post: 06-12-2009, 01:09 AM

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