Results 1 to 3 of 3

Problem displaying correct record:(

  1. #1
    Freddie81 is offline Competent Performer
    Windows 10 Access 2013 64bit
    Join Date
    Mar 2018
    Posts
    104

    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 offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    4,288
    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.
    - "doesn't work" is no help. What's happening? Error messages? Where??
    - Use code tags for code/sql. Implement changes in copies of your database.
    Irregardless, ain't no such word as "reoccur".

  3. #3
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    7,695
    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
    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. Replies: 2
    Last Post: 11-05-2017, 12:11 AM
  2. Replies: 0
    Last Post: 04-15-2016, 01:17 PM
  3. Form not displaying correct record
    By shadowsedge in forum Forms
    Replies: 2
    Last Post: 04-04-2016, 10:38 AM
  4. Replies: 3
    Last Post: 08-15-2013, 09:43 AM
  5. Replies: 2
    Last Post: 11-19-2012, 09: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
  •  
Tech Forums: Microsoft Office Forums