M
Matthew DeAngelis
Hi everyone,
Please bear with me; my coding skills are subpar.
I am trying to write some VBA code that will create a customized SQL
Update statement based on a series of "If" statements. Basically, I
want the sub to test a field to see if it is null and, if not, build
the SQL statement to include that field preceded by its name (ie
'Technology: ' & [Technology]). The SQL statement itself is updating a
memo field to include the information from a number of other fields (so
that I can delete those other fields).
Here is what I have so far:
Public Sub MergeMemoFields()
Set rst = New ADODB.Recordset
Set cnn = New ADODB.Connection
Set cnn = CurrentProject.Connection
rst.Open "[tbl: Data - Deals]", cnn
Dim strSQL As String
strSQL = "UPDATE [tbl: Data - Deals] SET [tbl: Data -
Deals].ConcatMemoField = "
If rst!Technology Is Not Null Then
strSQL = strSQL + "'Technology: ' & [tbl: Data - Deals].Technology
& Chr(13)+Chr(10)+Chr(13)+Chr(10)"
End If
If rst!IP Is Not Null Then
strSQL = strSQL + " & 'IP: ' & [tbl: Data - Deals].IP &
Chr(13)+Chr(10)+Chr(13)+Chr(10)"
End If
If rst!BusinessModel Is Not Null Then
strSQL = strSQL + " & 'Business Model: ' & [tbl: Data -
Deals].BusinessModel & Chr(13)+Chr(10)+Chr(13)+Chr(10)"
End If
If rst!Issues Is Not Null Then
strSQL = strSQL + " & 'Issues: ' & [tbl: Data - Deals].Issues &
Chr(13)+Chr(10)+Chr(13)+Chr(10)"
End If
If rst!MarketOpportunity Is Not Null Then
strSQL = strSQL + " & 'Market Opportunity: ' & [tbl: Data -
Deals].MarketOpportunity & Chr(13)+Chr(10)+Chr(13)+Chr(10);"
End If
End Sub
I haven't even gotten to running the SQL statement, because I am
getting an 'object required' error at the first If. However, when I
enter Debug mode and hover over rst!Technology, the correct value of
the field is displayed. I can also get the correct value by typing
?rst!Technology. If I reset the sub and type ?rst!Technology into the
Immediate Window, then I get the same 424 error. It would appear that
the system can see the value in debug mode, but not at run-time.
Any ideas?
Thanks,
Matt
Please bear with me; my coding skills are subpar.
I am trying to write some VBA code that will create a customized SQL
Update statement based on a series of "If" statements. Basically, I
want the sub to test a field to see if it is null and, if not, build
the SQL statement to include that field preceded by its name (ie
'Technology: ' & [Technology]). The SQL statement itself is updating a
memo field to include the information from a number of other fields (so
that I can delete those other fields).
Here is what I have so far:
Public Sub MergeMemoFields()
Set rst = New ADODB.Recordset
Set cnn = New ADODB.Connection
Set cnn = CurrentProject.Connection
rst.Open "[tbl: Data - Deals]", cnn
Dim strSQL As String
strSQL = "UPDATE [tbl: Data - Deals] SET [tbl: Data -
Deals].ConcatMemoField = "
If rst!Technology Is Not Null Then
strSQL = strSQL + "'Technology: ' & [tbl: Data - Deals].Technology
& Chr(13)+Chr(10)+Chr(13)+Chr(10)"
End If
If rst!IP Is Not Null Then
strSQL = strSQL + " & 'IP: ' & [tbl: Data - Deals].IP &
Chr(13)+Chr(10)+Chr(13)+Chr(10)"
End If
If rst!BusinessModel Is Not Null Then
strSQL = strSQL + " & 'Business Model: ' & [tbl: Data -
Deals].BusinessModel & Chr(13)+Chr(10)+Chr(13)+Chr(10)"
End If
If rst!Issues Is Not Null Then
strSQL = strSQL + " & 'Issues: ' & [tbl: Data - Deals].Issues &
Chr(13)+Chr(10)+Chr(13)+Chr(10)"
End If
If rst!MarketOpportunity Is Not Null Then
strSQL = strSQL + " & 'Market Opportunity: ' & [tbl: Data -
Deals].MarketOpportunity & Chr(13)+Chr(10)+Chr(13)+Chr(10);"
End If
End Sub
I haven't even gotten to running the SQL statement, because I am
getting an 'object required' error at the first If. However, when I
enter Debug mode and hover over rst!Technology, the correct value of
the field is displayed. I can also get the correct value by typing
?rst!Technology. If I reset the sub and type ?rst!Technology into the
Immediate Window, then I get the same 424 error. It would appear that
the system can see the value in debug mode, but not at run-time.
Any ideas?
Thanks,
Matt