[AccessD] Doin the class thing - was Re: Generic Procedure on form controls for Drag and Drop

John W Colby jwcolby at gmail.com
Thu Feb 7 08:33:23 CST 2013


John,

Create a little test database.
Create a form
Drag and drop 3 text boxes out.  When I did this they ended up with the names Text2, Text4 and 
Text6.  Make sure that your text boxes are named that or the code won't work as it is.

Open the form's code window and paste this in:

'#####################################
Option Compare Database
Option Explicit

'
'The quick and dirty way to do this
'
Private cDNDTxt2 As clsDNDText
Private cDNDTxt4 As clsDNDText
Private cDNDTxt6 As clsDNDText

Private Sub Form_Open(Cancel As Integer)
     Set cDNDTxt2 = New clsDNDText
     cDNDTxt2.mInit Text2

     Set cDNDTxt4 = New clsDNDText
     cDNDTxt4.mInit Text4

     Set cDNDTxt6 = New clsDNDText
     cDNDTxt6.mInit Text6

End Sub
'#####################################

Next insert a class module.  The 'how' changes between 2003 annd 2007 so I am leaving that up to you.

In that class module insert the following:

'#####################################
Option Compare Database
Option Explicit

Private WithEvents mtxt As TextBox
Private Const cEvProc As String = "[Event Procedure]"
Private Sub Class_Terminate()
     Set mtxt = Nothing
End Sub

Function mInit(ltxt As TextBox)
     Set mtxt = ltxt
     mtxt.OnDblClick = cEvProc
End Function

Private Sub mtxt_DblClick(Cancel As Integer)
     'Do something here
     MsgBox mtxt.Name & ".DblClick"
End Sub
'#####################################

Save everything.  Name the class clsDNDText.  The form name doesn't matter.

Open the form.  Double click in each text box.

John W. Colby

Reality is what refuses to go away
when you do not believe in it

On 2/6/2013 1:55 PM, John Bodin wrote:
> Hello,
>
>   
>
> New to this list and need some guidance on a form I've developed (I posted
> this on LinkedIn and got a few links with good information, but still having
> issues).
>
>   
>
> I have a grid of many text boxes on a form in an Access 2003 app that I fill
> from a table upon opening the form as well as when the user changes a date
> box. I add some generic procedure calls on the fly to each text box where I
> pass the control to the generic function (for instance, I'll add a
> double-click event to text box "Txt101" as "=TxtBoxDblClick([Txt101])". This
> will pass the control to my function TxtBoxDblClick so I can react to it.)
> This all works fine for all text boxes and I reference just one (same)
> routine for each control.
>
> I'm trying to experiment with Drag and Drop and found some code that I can
> get to work if at Design time, I add three event procedures to a text box
> control (Mouse Down/Up/Move). If I do this to two different controls,
> creating 3 event procedures for each at design time, I can successfully drag
> and drop between the two controls. So the drag and drop code looks like it
> works.
>
> My problem is, I want to have 3 generic routines like my TxtBoxDblClick
> function, that I can add on the fly to the On Mouse Down/Up/Move events and
> I can't figure out the syntax and/or code to make this happen. I can add the
> custom Functions no problem, but I know I need to be able to deal with the
> Button, Shift, X & Y parameters somehow. I can pass the control to the
> custom function, but am unable to reference the Button, Shift, X & Y
> parameters. I'm guessing I'll need to create some type of class possibly? If
> so, can someone provide some sample code on how to do this what the calls
> would be?  Thanks for any ideas. John
>
>   
>



More information about the AccessD mailing list