AccessWillKill
Registered User.
- Local time
- Today, 15:36
- Joined
- Oct 2, 2010
- Messages
- 50
Hello, i'm new to the forum and i've been working on this problem for the best part of a week. So far all was going well until i came to this issue.
I've recently started a new job which involves using access 2003 and VBA and was given a few tasks to do, as follows
I have successfully created a loop that cycles through the fields and gets the values inserted whether edited or not. And i have an SQL Statement that inserts fields into the edited field and the username of the person who inserted them (although the loop and the statement are not linked yet, as i have tested them individually not together yet)
However my loop cannot compare the value of the field in the loop with what was originally in the field.
i shall give you the code of the 'save' button i have created to perform this and comment what it does and the variables etc to give you an idea. if you need anymore information just say.
like i said i've really struggled with this part, i can't get my head around it.
I've recently started a new job which involves using access 2003 and VBA and was given a few tasks to do, as follows
- find or create code that can get a users login name (done)
- make a form that takes a snapshot of a user selected field for editing (done)
- Make the form save any edits to the selected fields in the form table (done)
- Make the form get all the edits from the selected table and log them in a new table (very stuck)
I have successfully created a loop that cycles through the fields and gets the values inserted whether edited or not. And i have an SQL Statement that inserts fields into the edited field and the username of the person who inserted them (although the loop and the statement are not linked yet, as i have tested them individually not together yet)
However my loop cannot compare the value of the field in the loop with what was originally in the field.
i shall give you the code of the 'save' button i have created to perform this and comment what it does and the variables etc to give you an idea. if you need anymore information just say.
Code:
Private Sub save_click()
Dim SQLstr As String
Dim Field As Integer
[COLOR="Green"]' prikey string1 and dateone are global variables Me!field1edit et all are the values when the save button is clicked, whether edited or not [/COLOR]
PriKey = Chr(34) & Me!PrimaryKeyFieldEdit & Chr(34)
String1 = Chr(34) & Me!Field1Edit & Chr(34)
DateOne = Me!Date1Edit
[COLOR="green"]' this is the update string which updates the fields in the table[/COLOR]
SQLstr = "UPDATE TwentyFieldTable SET TwentyFieldTable.field1 = " & [String1] & ", TwentyFieldTable.Date1 = #" & [DateOne] & "# WHERE (((TwentyFieldTable.PrimaryKeyField)= " & [PriKey] & " )); "
Debug.Print SQLstr
[COLOR="green"]'this is the for loop which is incomplete[/COLOR]
For Field = 1 To Me.Count - 1
[COLOR="green"]'this bit breaks the code[/COLOR]
If Me(Field).Value <> Me(Field).Value Then
[COLOR="green"]'this bit tells me whats value is in the field, for testing purposes mainly[/COLOR]
MsgBox ("field contains " & Me(Field).Value)
[COLOR="green"]'this is where IF the field has been altered the SQL Insert Statement (below will be placed)[/COLOR]
[COLOR="green"] 'elseIf field is the same then end if and continue the loop[/COLOR]
End If
Next Field
' Toggle the flag.
status = Not status
[COLOR="green"]'this is my insert statement with test values except getusername(), which goes to a module to get the users login name[/COLOR]
INSERT INTO project2 ( EditedField, oldvalue, newvalue, username )values( 'field1' , 'test' , 'test2' , getusername()) ;
DoCmd.SetWarnings False
DoCmd.RunSQL SQLstr
'DoCmd.Close , frmMassiveEdit
End Sub
like i said i've really struggled with this part, i can't get my head around it.
Last edited: