masoud
masoud

Reputation: 925

Opening new form after right click on selected record in continuous form

In my access database before I was using a list box in the form for having list of items and I had below code for opening new form after right click on each selected item in list box.

Private Sub ItemList_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Const RIGHTBUTTON = 2
    If Button = RIGHTBUTTON Then  
        DoCmd.OpenForm "frmShortcut_GenerateTask"
        DoCmd.MoveSize udtPos.X * mp.TwipsPerPixelX, udtPos.Y * mp.TwipsPerPixelY
    End If
 End Sub 

Now I am using a continuous form instead of list box and I have defined a [isselected) field for selecting each record in continuous form after clicking on that. Now my problem is how I have to write code for right clicking and opening new form.

I used the same code I had used for list box, but it does not work and nothing happened.

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    Const RIGHTBUTTON = 2
    If Button = RIGHTBUTTON Then  
        DoCmd.OpenForm "frmShortcut_GenerateTask"
        DoCmd.MoveSize udtPos.X * mp.TwipsPerPixelX, udtPos.Y * mp.TwipsPerPixelY
    End If
End Sub

Private Sub P_Click()
    On Error Resume Next
    Me.IsSelected = Not Me.IsSelected
    ' Save the status
    Me.Dirty = False
    ' Force conditional highlighting
    P_ForceHighLight
    ' Update display in SF_Selected
    Me.Parent("SF_Selected").Requery
    ActiveControl.SelLength = 0
    On Error GoTo 0
End Sub

Upvotes: 0

Views: 611

Answers (1)

HK1
HK1

Reputation: 12220

I recommend either using a DoubleClick event in all of your textboxes and combos, or else putting a small button at one edge of your continuous form that allows the user to open records. Right-click is going to give you problems (so will labels and image controls) because this event doesn't cause (or ensure) that the Form's internal Recordset Bookmark property is actually moved to the record they right-clicked on. In my experience, only buttons, textboxes, and comboboxes will move the Bookmark to the record the user is trying to select.

To Test this, try putting code at the top of your different routines that shows you what record is selected:

MsgBox "RecordID = " & Me!RecordIDField

If you are consistently getting the correct ID, then your problem has to do with how your opening your new form, passing parameters or arguments, etc.

Upvotes: 1

Related Questions