Solved

Event Actions and Flexgrid

Posted on 2002-04-23
6
1,034 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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…

762 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

21 Experts available now in Live!

Get 1:1 Help Now