Full Version: Open form on listbox click
UtterAccess Forums > Microsoft® Access > Access Forms
bekibutton
Hi,
I'm sure I've seen the answer to this somewhere on here, but I don't really know what I'm looking for. Any help is appreciated!
Basically I have a listbox showing the results of a search. I want my users to be able to click/double click on a record and a small form appear beside where the user clicked. This is basically a form with a couple of command buttons on it where the user can choose to complete or amend the record. How would I get it to show 'on' the clicked row in the listbox?
Thanks!
Becki
uarulez2.gif
bekibutton
*waves as the post disappears off the front page*
Alan_G
Hi
On the On Click or On Double Click event of your list box, put the following
DoCmd.OpenForm "NameOfFormYouWantToOpen", , , "[IDNo] = " & Me.YourListBoxName
assuming your listbox bound column is the AutoNumber ID field of the record you want to view and the form your opening's record source is the table itself. Change [IDNo] to whatever your table field is called.
HTH
Alan
bekibutton
OK that opens a form anywhere on the page. How could I get it to open next to my mouse click? shrug.gif
jhardy66
The only thing I can think of right now to do that is to take a look at this post by Mr. Hicks and learn how to acquire the XY coordinates of your mose. Then you could use the DoCmd.MoveSize function to move your form to those coordinates after it is opened.
Just an idea...probably not the best idea, but an idea nonetheless.
HTH
bekibutton
I just tried DoCmd.MoveSize (GetX(), GetY()) but it didn't like the parantheses... am i doing it wrong?

EDIT: Just looked it up and have realised the measurements must be in inches or cm...how do I do that when users might have different screen resolutions?


Edited by: bekibutton on Fri Oct 15 12:01:13 EDT 2004.
jhardy66
you could use variables:

Dim Xcoor As Int
Dim Ycoor As Int
Xcoor = GetX()
Ycoor = GetY()
DoCmd.MoveSize (Xcoor, Ycoor)

That should work...I haven't tested it, but it should work.

Actually, the MoveSize is in Twips...not Inches/cm. A twip is 1/1440 of an inch.
So if you need inches from a twip value, divide by 1440.
If you need twips from an inch value, multiply by 1440.
The screen resolution shouldn't affect this once you work in the math.
bekibutton
It asks me for an equals (=) sign after the [Right] and [Down] part. Then when I put = (Xcoor, Ycoor) it says it expects a bracket after the Xcoor. shrug.gif
bekibutton
OK I've got it doing that bit at least by removing the parantheses. However now although it moves a bit I think it's working in twips. I've tried doing
CODE
Xcoor = CInt(GetX()) * 1440

to get it into inches but it comes up with an overflow error. Help!
bekibutton
Can anyone help?
jhardy66
Could you post your complete code that you are using to do this with?
bekibutton
CODE
Dim Xcoor As Int
Dim Ycoor As Int
Xcoor = CInt(GetX()) * 567 <---to get it to cm    
Ycoor = CInt(GetY()) * 567
sgBox Xcoor & ", " & YCoor

DoCmd.MoveSize Xcoor, Ycoor
jhardy66
I have to leave the office for the rest of the day, but I will see what I can figure out codewise AS SOON as I get home tonight. Sorry about this, but work must come first.
bekibutton
S'ok - obviously work comes first! Everyone seems to be very busy today - must be that Monday feeling frown.gif Thanks for your help
uarulez2.gif
jhardy66
Sorry, I have been sick the last few days. I haven't been to work or school, much less foruming.

Try taking the "CInt" out of your code and see what happens.

CODE

im Xcoor As Int
Dim Ycoor As Int
Xcoor = (GetX()) * 567
Ycoor = (GetY()) * 567
MsgBox Xcoor & ", " & YCoor
DoCmd.MoveSize Xcoor, Ycoor
JeffK
What you're trying to accomplish is what customizable shortcut menus are for. I would use one of those instead of trying to worry about extra coding to move a form around.
o to Tools | Customize
Click [New] and type a name for your command bar
Click [Properties] and choose "Popup" as the type. The new command bar will disappear and you will get a message saying that you can find it under the shortcut menus
Close the Properties dialog and check the box next to "Shortcut Menus"
On the Shortcut Menus toolbar, click to expand [Custom] and you will see the bar you just named show up it
With your custom commmand bar expanded you can add controls to it.
Switch to the Commands Tab on the Customize dialog and drag the Custom Command onto your bar. Right-click on the Custom command to give it a new name, such as "Complete". Add another Custom command and rename it "Ammend".
Now you just need to assign the shortcut bar to your listbox and add tell it what code is supposed to run when you select a command. On your listbox's property sheet, set the Shortcut Menu Bar property on the Other tab to the name of your custom command bar. In a standard module, create a public function (not sub) to respond to each custom command. Let's say you name your functions fComplete() and fAmmend(). In the toolbar customize mode if you have the shortcut menu up you can right-click on a command and choose Properties. In the On Action box, type =fComplete().
Now when you right-click on the listbox it will open your custom shortcut menu and clicking on a command will run your public function.
For more help, type "custom shortcut" in Access help.
HTH
Jeff
bekibutton
Oooh that works really well Jeff! Thanks for your help! grin.gif

uarulez2.gif
EDIT: I swear something always goes wrong after I've said that...The trouble with the toolbar is I can't hide one of the buttons (AFAIK) if the item I'm clicking on has been completed. It's perfect apart from that!
Edited by: bekibutton on Wed Nov 3 10:23:00 EST 2004.
bekibutton
And Jonathan, unfortunately it came up with 'Overflow' again ... :(
bekibutton
Anyone have any ideas? shrug.gif
bekibutton
:bump:
JeffK
You can disable a command bar button, including any custom ones you include on a custom commandbar, with code like this:
ommandbars("ShortcutMenuBarName").Controls("CustomCommandName").Enabled = False
ShortcutMenuBarName is the name of your custom shortcut bar
CustomCommandName is the caption of any of the commands you dragged onto the bar - make sure you use the exact caption (including any accelerator & characters)
Good Luck!
Jeff
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.