Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drag and Drop on a table

Status
Not open for further replies.
Sep 13, 2002
4
US
I have a two part question; Can I highlight a record on a listbox or subform on my main form, and with the left mouse button highlight, drag, and drop it's value in another listbox or subform?

Also, along the same lines, can I put in "right click" abilites on fields within my listbox or subforms that open up other options to do to the record? Such as adding a value to it's field.

Any how to's are appreciated.
 
Not tried this before, but something worth a go..

Create a global variable in a module (eg GlobVar.strlstValue)

Now, the idea is that when you click and hold your mouse button, this is basically the "Mouse Down" event.. so create a Mouse down event for the first list box with the code:

Code:
lstbox.Value = GlobVar.strlstValue
'it would be sensible to have the primary key as the list box's value...

You could also change the mouse pointer at this stage.

Then, when you 'drag' over to the other listbox, create a "Mouse Up" event for the second list box. Assuming that this second list box has a record source of a different table, you would need to write the code to add the record to this table. I would suggest doing this by doing the following:

Mouse Up event code =
Code:
docmd.openform "frmlstDragAdd"

Create a formand name it "frmlstDragAdd"
Give the record source for this new form as the SECOND table and add all the fields of this second table to the form.

Fun part now.

Create an on open event. add the code:

Code:
docmd.gotorecord,,acnew
'for each field you'll need to look up the record value 
'from the global variable and add to fields on form.
dim strF1 as string
dim strF2 as string

strF1 =DLookUp("[FieldName1]","tblSecondTable","[PrimaryKey] = " & GlobVar.strlstValue)

Field1 = strF1

strF2 =DLookUp("[FieldName2]","tblSecondTable","[PrimaryKey] = " & GlobVar.strlstValue)

Field2 = strF2

docmd.close

FINALY!! Create an OnActivate event for the original form (where the two list boxes are) that refreshes the second list box and voila.. the record should appear.

This is the only idea that I could come up with as a solution.. Hope you can understand it, and hope it works for you!! I'm sure they may be a quicker way to do it, but I do not know what it is..

regards
Simon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top