Why does it =5? how do I change this value to represent the active record.
You would replace 5 with a variable. First declare a variable and then use the variable by concatenating to your WHERE clause.
Code:
Dim strSQL As String
Dim strNote As String
dim lngFieldID as long
lngFieldID = 5
strNote = InputBox("Reason for change:", _
"Rescheduling Tracker")
strSQL = "UPDATE TableName SET TableName.FieldName = '" & strNote & "' WHERE TableName.MyFieldID = " & lngFieldID
CurrentDb.Execute strSQL
I have made a macro which creates the audit record, I want the user entered note to be added to the last record added to the audit table. Am I asking too much with this?
If you use an embedded macro or a saved Macro Object to append a record, it is not likely you will know this record's PK value. So, determining what value to replace 5 with will be difficult. Why not replace the UPDATE statement in my previous example with an append query? This is why I will suggest creating a Query Object that performs the task you desire. You can name and save the Query Object or use the SQL statement generated by the query designer in your VBA.
This is what I'm using to reference, although my method is very different to how this works. This has an input box that comes up and then applies the user entered 'note' to the audit.
I avoid Macros when possible. They may seem easier to implement, but the reality is they have limits. When these limits are realized, the real work begins. Also, the use of input boxes seems like a good idea, but they rarely are. Before assigning a value to a field in a table, you need to do data validation. It is common practice to use Controls within forms to collect user input. I prefer to do data validation on controls.
I downloaded your example. I do not see any Macros. In Access, a Macro is an Object. When you record a macro in Excel, it is saved as VBA. When you record a macro in Access, it is saved as an Object and it has a Name. What you have in your example is not a Named and Saved Macro Object. You have some functions that create SQL statements and execute the statements. These functions are VBA procedures.
I did not look very carefully at the custom functions, but it seems you would have to make edits to the function in order to accept arguments for multiple columns. I would recommend using the approach I suggested earlier. Create an action query using the Query Designer.