Log in

View Full Version : Continous form - VBA solution for separating single datasets



linkerschuh
10-07-2014, 06:24 AM
Dear all,

I have the following problem:

- I created a continuous form, which displays, based on a query, datasets out of a table in which a specific field ("username2") is missing

- Username2 is supposed to be the current windows user, which is determined in a module ("modul3")

- This module also puts the username in an unconnected cell on the continuous form

- What I want to achieve is that behind each dataset on the continous form, there is a command button through which the user can re-confirm that this specific dataset is correct; after each OK click, the field "username2" for this specific dataset is subsequently updated in the table

- As it is a continous form, there are numerous datasets on it; the only code I manage to come up with is that in case any given OK button is clicked, all datasets in the table are updated, not the single one, after which the OK button is placed; the rest of the problem (reading user name, query, etc) is sorted out, but I don't achieve that only the single dataset in question is updated

Here is the current code (the only one working I could come up with):

Private Sub Umschaltfläche13_Click()

CurrentDb.Execute "UPDATE Base " & _
"SET Username2 = '" & Modul3.UserNameWindows & "'"

End Sub

Anybody an idea how this can be solved?

Thanks so much!!!

jonh
10-07-2014, 08:57 AM
If you can't just update the field in the form e.g.


Private Sub Command1_Click()
Me!Username2 = Environ("username")
End Sub

you need to tell the query which record you want to update. Is there a unique key/id in your table for each record?

UPDATE Base SET Username2 = '" & Modul3.UserNameWindows & "' Where id = " & me!recordid

linkerschuh
10-07-2014, 11:20 AM
Thanks for your help!

It's sorted out now, I made a mistake in the WHERE expression.