Results 1 to 10 of 10
  1. #1
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776

    DLookup A Field in Table and set a value to true ?

    Hi all,


    I am trying when I click button on my form, to look up a different table and set the IsPaid check box to true and not sure how to make that happen
    I have been trying different things but nothing seems to tick that checkbox.\

    TransBillID is in form and table to referencehes my field TransB
    I am seeking to set the IsPaid field to =True Where the TransBillID in tblTransBillLedger matches TransBillID on my form


    Code:
    Private Sub CmdPostPayment_Click()
    
    
    DLookup("TransBillID", "tblTransBillLedger", "TransBillID=" & forms!frmTransPayment!TransBillID)
        'Set field IsPaid to = True in tblTransBillLedger
        IsPaid = True
    End Sub
    Not sure how to actually write this to make this happen?
    Thanks for assistance
    Dave

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Me.IsPaid = Not IsNull(DLookup("TransBillID", "tblTransBillLedger", "TransBillID=" & forms!frmTransPayment!TransBillID))
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Hi June,
    Actually that does the oposit of what I am looking for, it un-ticks my IsPaid in my form and puts the value of the frmTransPayment IsPaid value.

    Here is full code on the button...

    Code:
    
    
    Code:
    Private Sub CmdPostPayment_Click()
        Dim strsql As String
        Dim db As DAO.Database
        Set db = CurrentDb
        
        If Me.IsPayrollDeduct = False Then
            strsql = "INSERT INTO tblAccountLedger (TransactionID, TransTypeID, TransCode, TransDate, AccountID, DescriptionID, TransMethodID, Debit) " & _
                "VALUES (" & TransactionID & ", " & CboTransType & ", '" & TransCode & "', #" & TransDate & "#, " & CboFromAccount & ", " & DescriptionID & ", " & CboTransMethod & ", " & TransAmount & ")"
            Debug.Print strsql
            db.Execute strsql, dbFailOnError
    
    
            strsql = "INSERT INTO tblAccountLedger (TransactionID, TransTypeID, TransCode, TransDate, AccountID, DescriptionID, TransMethodID, Credit) " & _
                "VALUES (" & TransactionID & ", " & CboTransType & ", '" & TransCode & "', #" & TransDate & "#, " & CboToAccount & ", " & DescriptionID & ", " & CboTransMethod & ", " & TransAmount & ")"
            Debug.Print strsql
            db.Execute strsql, dbFailOnError
    
    
    Else
            strsql = "INSERT INTO tblAccountLedger (TransactionID, TransTypeID, TransCode, TransDate, AccountID, DescriptionID, TransMethodID, Credit) " & _
                "VALUES (" & TransactionID & ", " & CboTransType & ", '" & TransCode & "', #" & TransDate & "#, " & CboToAccount & ", " & DescriptionID & ", " & CboTransMethod & ", " & TransAmount & ")"
            Debug.Print strsql
            db.Execute strsql, dbFailOnError
    End If
            Me.IsPaid = True
            Me.IsPaid = Not IsNull(DLookup("TransBillID", "tblTransBillLedger", "TransBillID=" & Forms!frmTransPayment!TransBillID))
        Me.RecordLock = True
        Call Form_Current
    
    
    End Sub



  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    No, it is not putting the value of the frmTransPayment IsPaid value, it is putting the result of IsNull() function. A DLookup returns a value if there is a match and Null if there is not.

    So what do you want the DLookup to do? Can't just have it hang out loose in code. It is a function returning a result and that must be received and dealt with by something. I wrap it in IsNull() and that result sets IsPaid.

    You stated "I am seeking to set the IsPaid field to =True Where the TransBillID in tblTransBillLedger matches TransBillID on my form". That's what the expression I gave should do. If there is no match then IsPaid is set to False.

    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Hi June,
    What i wanted to do is set the IsPaid field in the DLookUp to true in that table where the record matches the TransBillID,
    So, If I click the button on my form, it will set the value to true in the chkbox in the table "tblTransBillLedger" Where ID's match

    Currently it is setting the value in my form to the value in the dlookup IsPaid....

    Hope this makes sense, dlookup may not be the correct, maybe an update qry?
    Not real sure but when i click that button it needs to set that IsPaid field in
    tblTransBillLedger to = true

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Then yes, you need to do an SQL UPDATE action, not DLookup. DLookup retrieves data, doesn't change data.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    thanks June 7

  8. #8
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Would it look like this?
    DoCmd.RunSql UPDATE tblTransactionPayment INNER JOIN tblTransBillLedger ON tblTransactionPayment.IsPaid = tblTransBillLedger.IsPaid SET tblTransBillLedger.IsPaid = [tblTransactionPayment].[IsPaid];
    UpDate, Above does not work at all....
    Or something like this?

    DoCmd.RunSql UPDATE ("tblTransBillLedger" SET IsPaid = True WHERE "TransBillID=" & Forms!frmTransPayment!TransBillID)

    I have been looking over examples but have not come to one that examples this that i can comprhend...

  9. #9
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I prefer CurrentDb.Execute. And literal text must go between quote marks. Why would need a table JOIN? Don't you just want to update record(s) = TransBillID from the form? I thought you want to update field in tblTransBillLedger? UPDATE action requires a SET clause.

    CurrentDb.Execute "UPDATE tblTransBillLedger SET IsPaid = True WHERE TransBillID=" & Forms!frmTransPayment!TransBillID
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  10. #10
    d9pierce1 is offline Expert
    Windows 10 Access 2016
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Hi June7
    Oh My Heavens, that worked like a charm....
    Thank you so much
    Dave

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

Similar Threads

  1. Replies: 5
    Last Post: 01-20-2018, 03:40 PM
  2. Replies: 4
    Last Post: 09-03-2016, 10:59 AM
  3. Replies: 5
    Last Post: 07-29-2013, 09:17 PM
  4. Replies: 3
    Last Post: 01-09-2013, 03:39 PM
  5. Populating a field from another table using DLookup
    By Jamescdawson in forum Access
    Replies: 22
    Last Post: 03-16-2012, 09:59 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