?
Solved

Event Actions and Flexgrid

Posted on 2002-04-23
6
Medium Priority
?
1,055 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 400 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
Back Up Your Microsoft Windows Server®

Back up 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Suggested Courses

770 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