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

Recordset.Update won't work in KeyPress event WHY?? 1

Status
Not open for further replies.

Catrina

Programmer
Feb 11, 2000
70
0
0
US
I have a form that I want the user to be able to enter data into textboxes and use the ENTER key rather than the TAB key. This works fine searching for KeyAscii 13 on all my forms execpt ones dealing with a database. The database will not Update. Here is my code that doesn't work. It works fine if I put the Update in a command button click event. I even tried to use the click event in my sub, but it didn't work either. Hopefully someone can help, this makes no sense to me.

BTW The textboxes DataSource and DataField are set to the database via code.

Private Sub Text1_KeyPress(Index as Integer, KeyAscii as Integer)

Select Case Index
Case 0
Case 1 'This does NOT work
If KeyAscii = 13 then
KeyAscii = 0
rsAccess.Update 'rsAcces is the recordset
'Command1_Click 'goes to the click sub, but won't Update
MsgBox "Updated"
Exit Sub
End If
Case 2
Case 3
End Select

End Sub

Private Sub Command1_Click()
rsAccess.Update 'this works fine when the
End Sub 'command button is clicked



I really need to be able to update and use the ENTER key, as all my other forms use this method.

Thanks in advance for any help

Catrina
[sig][/sig]
 
could you try this

ADOname.Database.execute(SQLStatements)

[sig][/sig]
 
Hi catrina, do you use debugging while programming. ok leave that, why dont you try your code in the keyup event . Also why dont you use a function where update takes place only once. Why i am saying this is that u have used .update method at two places. This could turn out to be erraneous because you wouldnt have control over the user actions. Suppose the user after pressing the enter key in the last text field again clicks the command button.(just think of the scenario). I generally feel that if a communication to database is necessary then it should be done only once in the given scenario.

Moreover i didnt get your exact requirement, if you want to update the database for each of the enters the user use or after he enters the data in all the text boxes and you want to update when he presses enter in the last text box...please mail to gantibabu@yahoo.com with some details and you can expect the solution at the earliest...all the best...vijay [sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top