Solved

Event Actions and Flexgrid

Posted on 2002-04-23
6
1,051 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 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
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 different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

688 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