Results 1 to 10 of 10
  1. #1
    njliven1 is offline Novice
    Windows 10 Access 2007
    Join Date
    May 2022
    Posts
    7

    Double Click Function

    I have a list form and want to be able to click on a single item and then open another form with the detail for that item in the list.



    The code I am using is below. However I get a type mismatch error. The data type for the InvoiceNo fields do match, so I am confused as to why this is not work. Except for the fact that my fields are not integers they are text fields. Any help is appreciated. Thank you!

    Private Sub InvoiceNo_DblClick(Cancel As Integer)


    If IsNull(InvoiceNo) Then Exit Sub
    DoCmd.OpenForm "frm_invoice_sub2", , , "InvoiceNo=" & InvoiceNo

    End Sub

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,906
    For text fields surround with single quotes, unless value could have a single quote. I doubt an invoice number should?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    njliven1 is offline Novice
    Windows 10 Access 2007
    Join Date
    May 2022
    Posts
    7
    When I do that is opens the form, but it shows all the data in in the table, I just want the data associated with that InvoiceNo record.

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,906
    Make sure the where option is in the correct position?

    https://docs.microsoft.com/en-us/off...docmd.openform

    Post back what you have now
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    njliven1 is offline Novice
    Windows 10 Access 2007
    Join Date
    May 2022
    Posts
    7
    Still not working. the first comma in the code is the view, second one is filter and third one is for the WhereCondition. There is no filter and the where condition is the InvoiceNo. So the second one represents a filter and it is optional, but I think it needs to be there, so the third position represents the WhereCondition. Taking away one of the commas did not make a difference. Maybe it is the way I have my quotes? Just at a loss.

    Private Sub InvoiceNo_DblClick(Cancel As Integer)


    If IsNull(InvoiceNo) Then Exit Sub
    DoCmd.OpenForm "frm_invoice_sub2", , , "'InvoiceNo'=" & "'InvoiceNo'"

    End Sub

  6. #6
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,409
    For text you need

    “InvoiceNo =‘“ & invoiceNo & “‘“

  7. #7
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,973
    Code:
    DoCmd.OpenForm "frm_invoice_sub2", , , "InvoiceNo= & '"InvoiceNo"'"
    EDIT: The above code is wrong. Corrected in post #10
    Last edited by isladogs; 05-29-2022 at 09:45 AM.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  8. #8
    njliven1 is offline Novice
    Windows 10 Access 2007
    Join Date
    May 2022
    Posts
    7
    Thanks, it works now. Quotes get so confusing.

  9. #9
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,409
    "InvoiceNo= & '"InvoiceNo"'"
    sure about that Colin

  10. #10
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,973
    Oops
    Reminds me of the comment by Eric Morecambe about playing all the right notes but not necessarily in the right order.
    Here I applied that to the quotes
    Try again....

    Code:
    DoCmd.OpenForm "frm_invoice_sub2", , , "InvoiceNo='" & InvoiceNo & "'"
    Presumably the OP used your version (but with standard quote marks!)
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

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

Similar Threads

  1. Select ALL on Double Click
    By dweekley in forum Access
    Replies: 2
    Last Post: 05-08-2017, 10:27 AM
  2. Double Click Listbox
    By HelpDesk in forum Access
    Replies: 12
    Last Post: 06-29-2015, 10:38 AM
  3. Replies: 12
    Last Post: 07-11-2014, 01:54 PM
  4. double click to open
    By spleewars in forum Programming
    Replies: 7
    Last Post: 05-22-2012, 11:52 AM
  5. On Double Click go to Subform
    By Theremin_Ohio in forum Access
    Replies: 2
    Last Post: 03-30-2011, 08:03 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