none
Double Click event to execute command RRS feed

  • Question

  • Hi

    I have 2 different databases.  On one of them I have been able to put the following code on the double click to be able to close the report and open the form at the record which was double clicked.

    Private Sub WORKSNO_DblClick(Cancel As Integer)
    DoCmd.OpenForm "frmVehicleDetails"
    Forms!frmVehicleDetails.Form.Recordset.FindFirst "WORKSNO=" & Me.WORKSNO
    DoCmd.Close acReport, "rptProdProg"
    DoCmd.Close acForm, "frmStatusReports"
    End Sub

    I have tried to use the same code to do the same thing in another database but it will not work.  The only difference between the 2 WORKSNO fields is that in the DB where it works the field format is a number and in the DB that doesn't work, the field format is short text.

    Can you help please?


    Chris | UK

    Thursday, June 23, 2016 2:59 PM

Answers

  • You need to use quotes to delimit text fields:

    'You can use either this:
    
    Forms!frmVehicleDetails.Form.Recordset.FindFirst "WORKSNO='" & Me.WORKSNO & "'"
    
    ' or this:
    
    
    Forms!frmVehicleDetails.Form.Recordset.FindFirst "WORKSNO=" & Chr(34) & Me.WORKSNO & Chr(34)

    EDIT:  That second option is best for fields where you might expect single quotes in the data (such as a name field which micht include data like O'Brien, etc.)


    Miriam Bizup Access MVP


    • Edited by mbizup MVP Thursday, June 23, 2016 3:05 PM
    • Marked as answer by ChrisParkin Thursday, June 23, 2016 4:08 PM
    Thursday, June 23, 2016 3:03 PM

All replies

  • You need to use quotes to delimit text fields:

    'You can use either this:
    
    Forms!frmVehicleDetails.Form.Recordset.FindFirst "WORKSNO='" & Me.WORKSNO & "'"
    
    ' or this:
    
    
    Forms!frmVehicleDetails.Form.Recordset.FindFirst "WORKSNO=" & Chr(34) & Me.WORKSNO & Chr(34)

    EDIT:  That second option is best for fields where you might expect single quotes in the data (such as a name field which micht include data like O'Brien, etc.)


    Miriam Bizup Access MVP


    • Edited by mbizup MVP Thursday, June 23, 2016 3:05 PM
    • Marked as answer by ChrisParkin Thursday, June 23, 2016 4:08 PM
    Thursday, June 23, 2016 3:03 PM
  • Ah, I see.  Thanks Miriam.  Big help as always.

    Chris | UK

    Thursday, June 23, 2016 4:08 PM
  • Chris

    Just a little FYI - The double-click event fires the single click event before the code in the double-click event. So if you also use the Click event you will get both in sequence.


    Bill Mosca
    www.thatlldoit.com
    http://tech.groups.yahoo.com/group/MS_Access_Professionals

    Thursday, June 23, 2016 4:38 PM
  • Hi Bill, thanks for the FYI.

    Sorry for being a bit thick but I don't really get why I would use the same code on both the Click and Dbl Click events.

    No, no - Chris you idiot!! Sorry Bill, I think I've just twigged what you are saying...

    If I have a different instruction attached to the Click event, the Dbl Click would execute them both one after the other.

    If I've understood you correctly then I'm pleased you've advised me of that.  Although I have not done that before, hopefully if I ever do, and it all goes horribly wrong, I'll remember your advice.

    Thanks very much.


    Chris | UK

    Thursday, June 23, 2016 5:09 PM