denwaps
01-16-2013, 05:43 AM
Hello,
I am new to VBA and am trying to figure out the terminology in some existing code in one of our databases.
This code is executed upon a button click on one of the forms, and basically logs the information currently in the form into a log table (tblResearch_Comments in this case).
I'm a little confused as to what a lot of the shortcuts are at the top of the code, and was hoping someone could help me out.
Private Sub cmdSaveComments_Click()
With Me
If IsNull(.txtComments.Value) Then
Call Application.CurrentDb.Execute("DELETE * FROM tblResearch_Comments WHERE item_num = " & .txtItemNum.Value)
Call Application.CurrentDb.Execute("UPDATE tblSyncBypassRpt SET Comments = '', Done = 0 WHERE item = " & .txtItemNum.Value)
Else
Dim strDate As String: strDate = " :[" & Now() & "]"
If InStr(UCase(.txtComments.Value), "SKIPTIMESTAMP") <> 0 Then
strDate = ""
.txtComments.Value = Replace(.txtComments.Value, "SKIPTIMESTAMP", "")
End If
If isExisting Then
Call Application.CurrentDb.Execute("UPDATE tblResearch_Comments SET Comments = '" & Replace(.txtComments.Value, "'", "%^&*") & strDate & "', Research_Complete = " & IIf(IsNull(chkResearchComplete.Value), 0, chkResearchComplete.Value) & " WHERE item_num = " & .txtItemNum.Value)
Else
Call Application.CurrentDb.Execute("INSERT INTO tblResearch_Comments VALUES (" & .txtItemNum.Value & ",'" & Replace(.txtComments.Value, "'", "%^&*") & strDate & "', " & IIf(IsNull(chkResearchComplete.Value), 0, chkResearchComplete.Value) & ")")
End If
Call Application.CurrentDb.Execute("UPDATE tblSyncBypassRpt SET Comments = '" & Replace(.txtComments.Value, "'", "%^&*") & strDate & "', Done = " & IIf(IsNull(chkResearchComplete.Value), 0, chkResearchComplete.Value) & " WHERE item = " & .txtItemNum.Value)
End If
End With
Call DoCmd.Close(acForm, "frmResearchComments", acSaveNo)
End Sub
In the first couple lines, what does this mean?:
Comments = '', Done = 0 WHERE item = " & .txtItemNum.Value
Is this setting a shortcut where the comments box is now reffered to as " ?? Also, what does the & sign represent?
Later in the code, I'm getting very confused by all the symbols piled together, such as:
.txtComments.Value, "'", "%^&*"
Could someone explain what one of those last few Call lines means?
I am trying to figure this out so I can use similar logic to populate a different log table from user entered data in a form.
As you can see I'm a bit lost, so thank you for any help you can provide with this!
I am new to VBA and am trying to figure out the terminology in some existing code in one of our databases.
This code is executed upon a button click on one of the forms, and basically logs the information currently in the form into a log table (tblResearch_Comments in this case).
I'm a little confused as to what a lot of the shortcuts are at the top of the code, and was hoping someone could help me out.
Private Sub cmdSaveComments_Click()
With Me
If IsNull(.txtComments.Value) Then
Call Application.CurrentDb.Execute("DELETE * FROM tblResearch_Comments WHERE item_num = " & .txtItemNum.Value)
Call Application.CurrentDb.Execute("UPDATE tblSyncBypassRpt SET Comments = '', Done = 0 WHERE item = " & .txtItemNum.Value)
Else
Dim strDate As String: strDate = " :[" & Now() & "]"
If InStr(UCase(.txtComments.Value), "SKIPTIMESTAMP") <> 0 Then
strDate = ""
.txtComments.Value = Replace(.txtComments.Value, "SKIPTIMESTAMP", "")
End If
If isExisting Then
Call Application.CurrentDb.Execute("UPDATE tblResearch_Comments SET Comments = '" & Replace(.txtComments.Value, "'", "%^&*") & strDate & "', Research_Complete = " & IIf(IsNull(chkResearchComplete.Value), 0, chkResearchComplete.Value) & " WHERE item_num = " & .txtItemNum.Value)
Else
Call Application.CurrentDb.Execute("INSERT INTO tblResearch_Comments VALUES (" & .txtItemNum.Value & ",'" & Replace(.txtComments.Value, "'", "%^&*") & strDate & "', " & IIf(IsNull(chkResearchComplete.Value), 0, chkResearchComplete.Value) & ")")
End If
Call Application.CurrentDb.Execute("UPDATE tblSyncBypassRpt SET Comments = '" & Replace(.txtComments.Value, "'", "%^&*") & strDate & "', Done = " & IIf(IsNull(chkResearchComplete.Value), 0, chkResearchComplete.Value) & " WHERE item = " & .txtItemNum.Value)
End If
End With
Call DoCmd.Close(acForm, "frmResearchComments", acSaveNo)
End Sub
In the first couple lines, what does this mean?:
Comments = '', Done = 0 WHERE item = " & .txtItemNum.Value
Is this setting a shortcut where the comments box is now reffered to as " ?? Also, what does the & sign represent?
Later in the code, I'm getting very confused by all the symbols piled together, such as:
.txtComments.Value, "'", "%^&*"
Could someone explain what one of those last few Call lines means?
I am trying to figure this out so I can use similar logic to populate a different log table from user entered data in a form.
As you can see I'm a bit lost, so thank you for any help you can provide with this!