Hi - I think the answer to this will mean much leaner databases for me in future.... In a nutshell, I have a form that looks at an attendance table, and all data can be amended on the form if needs be except the User, as it has a foreign key in the attendance table, but I need to reselect by the full name from a combo. So I created a button that opens a small form, has the combo look at the user table retrieving the UserID field and the FullName field. Then I wanted to run an Update statement from a cmd button on that little form that says:
Private Sub cmdUpdate2_Click()
Update tblEventAttdSU
Set tblEventAttdSU.ServiceUser = [Forms]![frmUpdateSUAttd]![txtSU_ID]
WHERE [Forms]![frmUpdateSUAttd]![txtEvtAttSU_ID] = [tblEventAttdSU].[EvtAttSU_ID]
End Sub
The statement fails with 'Compile error: sub or function not defined'. I think this has happened in the past, and I have just done what I have just done now - ie create a query using the access create query function, which works perfectly and is more or less the same code, but SQL is compiled by the graphic query creator. This means I often end up with loads more query objects in my database than is necessary, I should just be able to run this update with a couple of lines of code from the form. Am I not declaring something, missing some other modifying code?
BTW the code from the query is similar:
UPDATE tblEventAttdSU SET tblEventAttdSU.ServiceUser = [Forms]![frmUpdateSUAttd]![txtSU_ID]
WHERE (([Forms]![frmUpdateSUAttd]![txtEvtAttSU_ID]=[tblEventAttdSU].[EvtAttSU_ID]));
Many Thanks for reading this.
Private Sub cmdUpdate2_Click()
Update tblEventAttdSU
Set tblEventAttdSU.ServiceUser = [Forms]![frmUpdateSUAttd]![txtSU_ID]
WHERE [Forms]![frmUpdateSUAttd]![txtEvtAttSU_ID] = [tblEventAttdSU].[EvtAttSU_ID]
End Sub
- Table = tblEventAttdSU (record of user service user attendance)
- UserID = ServiceUser (Number - which I want to put into the attendance table from the little form where the event id in the table matches the event id in the form.)
- txtSU_ID = equivalent ServiceUserID on the update userid form)
- EvtAttSU_ID = the Attendance ID in the Attendance table.
- txtEvtAttSU_ID = the Attendance ID in the attendance form.
The statement fails with 'Compile error: sub or function not defined'. I think this has happened in the past, and I have just done what I have just done now - ie create a query using the access create query function, which works perfectly and is more or less the same code, but SQL is compiled by the graphic query creator. This means I often end up with loads more query objects in my database than is necessary, I should just be able to run this update with a couple of lines of code from the form. Am I not declaring something, missing some other modifying code?
BTW the code from the query is similar:
UPDATE tblEventAttdSU SET tblEventAttdSU.ServiceUser = [Forms]![frmUpdateSUAttd]![txtSU_ID]
WHERE (([Forms]![frmUpdateSUAttd]![txtEvtAttSU_ID]=[tblEventAttdSU].[EvtAttSU_ID]));
Many Thanks for reading this.