Solved

Event Actions and Flexgrid

Posted on 2002-04-23
6
1,040 Views
Last Modified: 2012-06-27
I am using Access97. In it I have a form with a flexgrid control on it. To mimick tab movements within the flexgrid and to allow users to add data to the flexgrid I have a textbox that I move over the top of the flexgrid. The user thinks that they are entering data into the flexgrid, but in actuallity they are entering the data into the textbox, and the program is filling in the flexgrid.

My problem.
I am trying to capture mousedown events. In order to use the tab (which does not work in a flexgrid) I have a lostfocus routine that when the the textbox loses the focus, it "tabs" to the next field. I am trying to have the program catch mousedown events, so that if a user uses the mouse to move to a different grid rather than the next grid in the control, it goes there. my coding is as follows:
'***************

Private Sub flxRevObjDetail_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Long, ByVal y As Long)
    usingMouse = True
    flxRevObjDetail.Text = txtFlxGridInput2.Text
    ChangeCelltext
End Sub

'***************
Private Sub txtFlxGridInput2_LostFocus()
    If usingMouse = True Then 'if using mouse, then ignor rest
        usingMouse = False
        Exit Sub
    End If
   
    flxRevObjDetail.Text = txtFlxGridInput2.Text
   
    If flxRevObjDetail.Col < flxRevObjDetail.Cols - 1 Then
        If flxRevObjDetail.Col = 0 And txtFlxGridInput2.Text = "" Then
            txtNotes.SetFocus
        Else
            flxRevObjDetail.Col = flxRevObjDetail.Col + 1
            flxRevObjDetail.SetFocus
            ChangeCelltext
        End If
    Else
        If flxRevObjDetail.Row = flxRevObjDetail.Rows - 1 Then
            flxRevObjDetail.AddItem ""
        End If
        flxRevObjDetail.Row = flxRevObjDetail.Row + 1
        flxRevObjDetail.Col = 0
        flxRevObjDetail.SetFocus
        ChangeCelltext
    End If
           
End Sub

The problem is the this LostFocus Event fires BEFORE the Mousedown event. Is there a different way I can check to see if the mouse was they previous thing used?

0
Comment
Question by:lyners
  • 4
  • 2
6 Comments
 
LVL 7

Expert Comment

by:Nosterdamus
ID: 6965278
Hi lyners,

Try using the OnClick Event instead.

HTH,

Nosterdamus
0
 
LVL 1

Author Comment

by:lyners
ID: 6966078
Thanks for the advise. I have researched this further and have found out the following....

Order of events when the mouse is clicked..

First Control..
Exit -> Lost Focus

Second Control..
Enter -> Got Focus -> MouseDown -> MouseUp -> Click

The Click event is the last thing, The lost Focus event is where the moving of the text box occurs. At this moment I still do not see how I am going to detect the mouse click prior to the lostfocus procedure.
0
 
LVL 7

Accepted Solution

by:
Nosterdamus earned 100 total points
ID: 6968190
Hi lyners,

After a little thinking, I'd like to share with you an idea that crossed my mined:

Say that there a 2 means to go from "one" textbox in the flexgrid to "another" ("one" and "another" are in double-quotes because you actualy are using a dummy textbox to get the user input):
1. By pressing Tab or Enter -> KeyBoard
2. By Clicking the flexgrid on the desired box

Since Mouse events occures AFTER the textbox control has lost focus, maybe the answer lies in the keyboard events.

If that is so, lets monitor the keystrokes in the textbox, and set UsingMouse, when ever Non Tab and Non Reurn keys are pressed. If they are pressed, then you want it to akt as if a Tab is pressed.

If this logic is acceptable, then I suggest to perform the following changes in your code:

1. You do not need Sub flxRevObjDetail_MouseDown any longer.

2. Place the following code in the KeyDown Event of txtFlxGridInput2:
Private Sub txtFlxGridInput2_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyTab Or _
       KeyCode = vbKeyReturn Or _
       KeyCode = vbKeyEscape Then
        usingMouse = False
    Else
        usingMouse = True
    End If
End Sub

3. Adjust the begining of Sub txtFlxGridInput2_LostFocus() to the following code:
Private Sub txtFlxGridInput2_LostFocus()
   If usingMouse = True Then 'if using mouse, then update Text and ignor rest
       flxRevObjDetail.Text = txtFlxGridInput2.Text
       ChangeCelltext
       usingMouse = False
       Exit Sub
   End If

HTH,

Nosterdamus
0
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
LVL 7

Expert Comment

by:Nosterdamus
ID: 6968198
Correction:

If that is so, lets monitor the keystrokes in the textbox, and set UsingMouse, when ever Non Tab and Non Reurn keys are pressed. If they are pressed, then you want it to akt as if a Tab is pressed.

Should read:
If that is so, lets monitor the keystrokes in the textbox, and set UsingMouse, when ever Non Tab and Non Return keys are pressed. If they are pressed, then you want it to act as if a Tab is pressed.

In addition:
The rest of Sub txtFlxGridInput2_LostFocus() should stay as is...


;-)

Nosterdamus
0
 
LVL 1

Author Comment

by:lyners
ID: 6968859
Excellent Idea. A couple things with this to make it work effectively.

-I had to leve the mouse down. This assitted me if I entered the flexgrid control through a mouse click.

-Also I had to add a routine in every controls onEnter function so that the textbox was shrunk back down to a size nobody could see.

Thanks, This worked great!

:-)
Lyners
0
 
LVL 7

Expert Comment

by:Nosterdamus
ID: 6974604
Hi lyners,

Glad I could help & good luck with your app.

;-)

Nosterdamus
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now