Joel Pomerantz
asked on
code to set focus on open to placeholder record on datasheet subform
Hello! I have a subform that opens in datasheet view. I'm looking for a way to set the focus on open to the placeholder record so that users don't accidentally overwrite previous data. I'm assuming this would be a pretty simple code but I don't know what you "call" the blank "placeholder" record :) thanks!!
ASKER
cool! ok, that works perfectly to set it when the form orriginally loads - but this datasheet is a subform linked to parent form by ID number... is there a way to keep the focus on the new record as the user scrolls (on the parent form) to different records? I tried on got focus, on activate, and a few others and can't figure out which event it would be! I'm assuming this is just a matter of putting your code into the correct event right?
Sure ... sorry ... put this in the On Current of the Main form:
Private Sub Form_Current()
Me.YourSubFormControlName. SetFocus.
Me.YourSubFormControlName. Form.SetFo cus.
Docmd.RunCommand acCmdRecordsGoToNew
End Sub
Private Sub Form_Current()
Me.YourSubFormControlName.
Me.YourSubFormControlName.
Docmd.RunCommand acCmdRecordsGoToNew
End Sub
Sorry .. ignore the last post.
mx
mx
Here you go:
put this in the On Current of the Main form:
Private Sub Form_Current()
Me.YourSubFormControlName. SetFocus
Docmd.RunCommand acCmdRecordsGoToNew
End Sub
I just tested this.
mx
put this in the On Current of the Main form:
Private Sub Form_Current()
Me.YourSubFormControlName.
Docmd.RunCommand acCmdRecordsGoToNew
End Sub
I just tested this.
mx
ASKER
cool! - it works great for me as well - there is just one bug I think... when I get to the end of the records (scrolling with command buttons) or, when I try to navigate to a record using the lookup combo box - it gives me the following error:
Runtime Error 2046:
the command or action 'RecordsGoToView' isn't available now
is there something we can add to fix that?
I really really appreciate your help!!
Runtime Error 2046:
the command or action 'RecordsGoToView' isn't available now
is there something we can add to fix that?
I really really appreciate your help!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
second method was the one that worked. I can't thank you enough!!!
mx, I hope that this is not a violation of EE protocol, but can I ask you to help me with
https://www.experts-exchange.com/questions/23849951/looking-for-function-to-search-for-a-specific-value-in-a-table-field.html
I'm not having much luck with that one and I think it's right up your alley :)
mx, I hope that this is not a violation of EE protocol, but can I ask you to help me with
https://www.experts-exchange.com/questions/23849951/looking-for-function-to-search-for-a-specific-value-in-a-table-field.html
I'm not having much luck with that one and I think it's right up your alley :)
ASKER
worked perfectly -- thanks so so so much for your time!!!
You are welcome ...
mx
mx
ASKER
uh oh - slight side effect... I'm going to open a new question for ya - but I wanted to give you a heads up here. thanks so much mx
Docmd.RunCommand acCmdRecordsGoToNew
End Sub
mx