I'll try to explain what my problem is and hopefully someone can give me an
I have a couple of textfields which I've bound to an Access-DB like this:
txtSample1.DataSource = rs
Set txtSample1.DataField = "Sample1"
txtSample2.DataSource = rs
Set txtSample1.DataField = "Sample2"
txtSample3.DataSource = rs
Set txtSample1.DataField = "Sample3"
txtSample4.DataSource = rs
Set txtSample1.DataField = "Sample4"
I'm using an explicit Update / Cancel button, to make sure nothing changes
the Update button is pressed. The update works fine. But the cancel-button
works ok as long as you're only using the mouse or TabKey. But I have a
code which uses the EnterKey to set the focus on the next textfield:
Private Sub txtSample1_KeyPress(KeyAscii As Integer)
'Go to the following textfield
If KeyAscii = vbKeyReturn Then
KeyAscii = 0
The problem is, when I'm using the EnterKey to go to the next textfields,
then decide to cancel the update, it only cancels the field where my cursor
in and he's updating the other fields (which isn't the case when using Tab
the mouse). The strange thing is, he hasn't updated the database until I
the Cancel-button, which invokes a 'recordset.CancelUpdate'. So the old
are still there, but using a cancelupdate, it makes the changed fields,
the cursor isn't in, do an update on the Database.
So, I can get the old values back by doing this before running the
txtSample1 = rs.Fields("Sample1")
txtSample2 = rs.Fields("Sample2")
txtSample3 = rs.Fields("Sample3")
txtSample4 = rs.Fields("Sample4")
But I don't think it's a nice (and necessary) way to do... besides, if the
Database-Field is empty, it can give a problem saying 'Invalid use of Null'.
I was completely surprised and I haven't got a clue why he's doing this. I
really want to keep using the EnterKey, because it's much easier for my
Hope someone has an idea... Big thanks in advance!!!