Results 1 to 3 of 3
  1. #1
    Freddie81 is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2018
    Posts
    149

    Problem displaying correct record:(

    Im building a Datasheet showing transactions (invoices and payments). I want to have the user click on the InvTotal field on the sheet and this opens a form called TransactionF. On this form, it shows info from a union query. The problem is It only shows the same record no matter which record I click on. How can I get it to check the invoice number (When I click the amount field it should check the invoice ID and only show the records for that specific invoiceID)
    My code currently is
    Private Sub InvTotal_Click()
    Const DataForm As String = "TransactionF"
    If Not IsNull(InvTotal) Then
    DoCmd.OpenForm DataForm, WhereCondition:="[InvoiceID]=" & [InvoiceID] & ""
    Else
    MsgBox "Oops"
    'DoCmd.OpenForm DataForm


    'DoCmd.GoToRecord , , acNewRec
    End If
    End Sub

  2. #2
    Micron is online now Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,788
    Try moving your event to the Current event of the form, which can give you the value from the field/control you ask for that pertains to the particular record that you select. IIRC, your current method will always return the 1st record.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Since you want to open a form from the control, I changed the event to the double click event.
    And I don't like negative logic (NOT IsNull() ), so I changed the order of the IF() test.

    Try this:
    Code:
    Option Compare Database  '<<-- should be at top of EVERY Module
    Option Explicit          '<<-- should be at top of EVERY Module
    
    Private Sub InvTotal_DblClick(Cancel As Integer)
        Const DataForm As String = "TransactionF"
    
        '#############################
        'for debugging - comment out/delete the following line after debugging
        MsgBox "InvTotal = " & Nz(Me.InvTotal, "NULL") & ";  InvoiceID = " & Nz(Me.InvoiceID, "NULL")
        '#############################
    
    
        If IsNull(Me.InvTotal) Then
            MsgBox "Oops"
            'DoCmd.OpenForm DataForm
            'DoCmd.GoToRecord , , acNewRec
        Else
            DoCmd.OpenForm DataForm, WhereCondition:="[InvoiceID]=" & Me.InvoiceID
        End If
        
    End Sub

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

Similar Threads

  1. Replies: 2
    Last Post: 11-05-2017, 01:11 AM
  2. Replies: 0
    Last Post: 04-15-2016, 02:17 PM
  3. Form not displaying correct record
    By shadowsedge in forum Forms
    Replies: 2
    Last Post: 04-04-2016, 11:38 AM
  4. Replies: 3
    Last Post: 08-15-2013, 10:43 AM
  5. Replies: 2
    Last Post: 11-19-2012, 10:54 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