Positioning a pop-up Calendar

J

jamesker

Hi,

I have a continuous form with a date field in it. beside the date
field, i've made a command button that when pressed, displays a
calendar form which allows users to choose a date, once a date is
chosen, the calendar form closes and the value chosen gets transfered
into the date field.

I want to make it so that the calendar form always appears next to
the
button when pressed, right now it just pops up in the middle of the
screen each time. I'm not sure if there's some sort of way to write
a
VB code that can read the position of the button that's just been
pressed and then relay that information to the calendar form and use
it to set it's position?! I know you can move forms with
docmd.movesize but i
can't get it to move to the button when pressed. if anyone out there
has any
suggestions on how to do this i'd greatly appreciate it! thanks.
 
K

Klatuu

You can read a buttons position by using the Left and Top properties of the
button. It will be expressed in twips. 1" = 1440 twips.

As to the calendar control, I don't know which control you are using, so I
can't help with that exactly except to say that most visible objects use the
Left and Top for positioning.
 
J

jamesker

OK so i tried to do what you suggested and it didn't work, this is the
code i have:

Private Sub Command2_Click()
Dim right, down As Long
right = Me.Command2.Left
down = Me.Command2.Top

DoCmd.OpenForm "Calendar"
DoCmd.MoveSize right, down
End Sub

it opens the "calendar" form and positions it to around the right
place for the first record in the continuous form, but when i go to
any other record and press the button, it just positions it to the
same place as when i pressed the button on the first record. I think
it is reading the position of the command button in design veiw and is
using only that one position for the coordinates. is there some way
of maybe reading the coordinates of my mouse position when i press the
button and getting the form to move to that location?
 
K

Klatuu

Glad you got it. Mine would work in a single form, I forgot about yours
being continuous.
I kept a copy of that form my bag of tricks.
Thanks.
 
C

CenturionX

Hello,

Try this:

Let's suppose that you command button name is Command1
and the calendar form name is frm_Calendar:

Private Sub Command1_Click()
Dim lL, lT As Long
lL = Me.WindowLeft + Me.Command1.Left + Me.Command1.Width + 345
lT = Me.WindowTop + Me.Command1.Top + Me.Command1.Height - 200
Forms("frm_Calendar").Move lL, lT
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top