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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Add a keystroke combination to an Event Sub 1

Status
Not open for further replies.

BearTrap3

IS-IT--Management
Jul 7, 2004
18
US
Hi all...

I am having problems getting a form to save the record in its underlying table, using a command button (WITHOUT closing the form) I know you can Shift-Enter to force-save a record in a form that is not closed yet. Are you able to add that keystroke sequence in VB Code so I can add it to a form event??

Thanks in advance for your help!!!

Fred
 
If your controls are unbound then you can use the following code to save the data to the table by using a command button.

Private Sub Command??_Click()

Dim cnn As ADODB.Connection
Dim rs As ADODB.Recordset

Set cnn = CurrentProject.Connection
Set rs = New ADODB.Recordset

strsql = "SELECT * FROM tablenamehere"

With rs
Set .ActiveConnection = cnn
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.Open strsql

.AddNew
![TableField1] = Me.FormFieldName1
![TableField2] = Me.FormFieldName2
.Update

End With

rs.Close
cnn.Close
 
And what about this ?
DoCmd.RunCommand acCmdSaveRecord

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thanks for your quick response.

Unfortunately, ALL of my controls are bound to fields in the underlying table. I really just want to include the keystroke sequence of Shift-Enter in the code already existing in the command button. This command button hides the current form and opens a subform.

Is there a way to just do that??

Thanks!
 
Thank you PHV!! You saved me lots of time! One STAR to you! :)

Fred
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top