Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datasheet Form Row Selection 1

Status
Not open for further replies.

mgabbert

Programmer
Sep 25, 2003
9
0
0
US
What I want to do is have a datasheet with X columns, and when you click in any of the cells, the whole row is selected.

Everything will work for me as long as I click on the row markers, and not in the individual cells. If I set SelTop, I can choose cells, but I am not able to select a whole row from an individual cell.

-matt

 
I'm not entirely sure what you're attempting, but have you tried:

[tt]docmd.runcommand accmdselectrecord[/tt]

in the on click event of the controls? This could make it a bit awkward to edit controls, though.

Roy-Vidar
 
okay, this was exactly what I was looking for and I must thank you. I often forget about docmd and resort to looking for control methods and such.

I wasn't sure exactly what you meant by controls, but it may be the next question I have.

The solution works as below:

Private Sub Detail_DblClick(Cancel As Integer)
MsgBox ProjectAcronym
End Sub

Private Sub Form_Click()
DoCmd.RunCommand acCmdSelectRecord
End Sub

Private Sub Form_DblClick(Cancel As Integer)
Call Form_Click
MsgBox (Me.ActiveControl)
End Sub

Private Sub ProjectID_Click()
Call Form_Click
End Sub

Private Sub ProjectID_DblClick(Cancel As Integer)
Call Form_DblClick(0)
End Sub

As you can see, for each column I have to pass the message to the form functions. Is there a way to automatically set this function for all controls in the datasheet?

I tried the following, but it did not work. I have to admit that I don't know all the tricks to vba yet.

Private Sub Form_Load()
Dim ctl As Control
For Each ctl In Me.Detail.Controls
'MsgBox ctl.ControlName ' to make sure i got it
ctl.OnClick = Me.OnClick 'this would be nice
Next ctl
End Sub

thank you again
-matt
 
I can't say I understand what you're attempting anymore now, but when I want to have the same thing happening on clicking controls, I use the same call for each control (btw - controls are the thingies on forms and reports, fields resides in tables or are retrieved thru queries, a control can be bound to a field). I've found using click events on the form or form sections doesn't always produce the results I'm after (they simply don't fire when i need).

[tt]private sub OneOfTheControls_Click()
call someroutine(me!OneOfTheControls)
end sub

private sub someroutine(ctl as control)
' some useful code for the passed control
end sub[/tt]

The control looping, are you trying to set the .OnClick property of the control equal to the forms .OnClick event? Wouldn't it be better to just call a/the routine, passing an arguement (or use a public variable to store the arguement, if you're calling a form event procecdure)?

Remember also when using the dbl click event, that the click event will also fire, prior to firing the dbl click event. There might be some tips regarding control looping in this faq faq702-5010. Else, to be of some assistance, I think I'd need to understand a bit more of what you're attempting to do, or perhaps someone else can pop in?

Roy-Vidar
 
I am trying to avoid the following:
private sub OneOfTheControls_Click()
call someroutine(me!OneOfTheControls)
end sub

I would like to use the loop to automatically set every control in the form to have the same onclick method. This way I can change the columns and reuse the form many times easily. It really isn't that important compared the the question you already answered for me.

I see what you mean about the click method being called in doubleclick. Thank you

-matt
 
Think this is getting beyond my capabilities;-)

You know, since you've alredy used it, that you can pass the activecontrol in such on click sub, in stead of "hardcoding" the control name:

[tt] call someroutine(me.activecontrol)[/tt]

- but I think that's the most I'm able to do in terms of doing this a bit more dynamic.

I've seen the usage of the .OnClick property in terms of changing between a macro, expression and the onclick event, but not seen how it might apply to, say change from the <control>_click to another routine.

There are methods of altering code modules, inserting code etc... but I think I'll leave that subject to others with experience;-)

(found two threads with some information, thread705-787184, thread705-550653, but... perhaps try some searching, if it's doable, one should be able to find something here;-))

Good Luck

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top