VBA Syntax Question

A

AJ

I am using a "switch" command on an insert and having trouble on breaking the
end of line in vba. (While still in the switch.) Can anyone help?
This is just a snipet of the code, but how do I continue a line in VBA
between PR01 and FIELD2?? (I put in question mark ?? where I want to break
the line.

Example:
insert into report_data_prior ( store, period, amount) " & _
"values ( '" & hv_store& "', '" & Switch(field1 =
"test1", pr01,?? field2 = "test2", pr02)

I cannot seem to figure ou the syntax because it is all within the
parenthesis.

Thanks
 
D

Dirk Goldgar

AJ said:
I am using a "switch" command on an insert and having trouble on breaking
the
end of line in vba. (While still in the switch.) Can anyone help?
This is just a snipet of the code, but how do I continue a line in VBA
between PR01 and FIELD2?? (I put in question mark ?? where I want to break
the line.

Example:
insert into report_data_prior ( store, period, amount) " & _
"values ( '" & hv_store& "', '" & Switch(field1 =
"test1", pr01,?? field2 = "test2", pr02)

I cannot seem to figure ou the syntax because it is all within the
parenthesis.


Is the Switch expression intended to be inside the SQL literal or outside
it? I guess that it's outside it, and field1, field2, pr01, and pr02 are
controls on the current form or variables in the procedure. In that case,
you could do it like this:

Dim strSQL As String

strSQL = _
"insert into report_data_prior (store, period, amount) " & _
"values ( '" & hv_store & "', '" & _
Switch(field1 = "test1", pr01, _
field2 = "test2", pr02) & _
"' )"

In principle, any place you could have a space, you could follow that space
with an underscore and continue on a new line.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top