Solved

Event Actions and Flexgrid

Posted on 2002-04-23
6
1,044 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

821 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