D
Don
I have a lengthy SQL string in my VBA code. Using line continuation and
character and concatenation, I've tried to appease the compiler.
However, I keep getting Expected errors. I think that there are
limitations to SQL strings in VBA i.e. lines and characters. From
reading other posts, I see that multiple occurences of strSQL can be
used too. I've tried coding this string different ways with no luck.
Can someone take a look at this code and help me reformat it properly
so that it doesn't keep giving me compile errors?
I'm pretty sure that I need to break it up so that I have
strSQL="Select * From "
strSQL=strSQL&"Where"
And so on.
Here's my code:
Dim strSQL As String
strsql = "SELECT * FROM "&InventorySource&""&_
"WHERE(((["&InventorySource&"].NRMU_NO_1=Forms.frmMainSearch.NRMU_NO_1)
Or (Forms.frmMainSearch.NRMU_NO_1) Is Null)"&_
"And ((["&InventorySource&"].USETYPE=Forms.frmMainSearch.USETYPE) Or
(Forms.frmMainSearch.USETYPE) Is Null)"&_
"And ((["&InventorySource&"].LANDCOVER=Forms.frmMainSearch.LANDCOVER)
Or (Forms.frmMainSearch.LANDCOVER) Is Null)"&_
"And ((["&InventorySource&"].DOM1=Forms.frmMainSearch.DOM1) Or
(Forms.frmMainSearch.DOM1) Is Null)"&_
"And ((["&InventorySource&"].DOM2=Forms.frmMainSearch.DOM2) Or
(Forms.frmMainSearch.DOM2) Is Null)"&_
"And ((["&InventorySource&"].DOM3=Forms.frmMainSearch.DOM3) Or
(Forms.frmMainSearch.DOM3) Is Null)"&_
"And ((["&InventorySource&"].AGE2SP1=Forms.frmMainSearch.AGE2SP1) Or
(Forms.frmMainSearch.AGE2SP1) Is Null)"&_
"And ((["&InventorySource&"].AGE2SP2=Forms.frmMainSearch.AGE2SP2) Or
(Forms.frmMainSearch.AGE2SP2) Is Null)"&_
"And ((["&InventorySource&"].AGE2SP3=Forms.frmMainSearch.AGE2SP3) Or
(Forms.frmMainSearch.AGE2SP3) Is Null)"&_
"And ((["&InventorySource&"].MGTCON=Forms.frmMainSearch.MGTCON) Or
(Forms.frmMainSearch.MGTCON) Is Null)"&_
"And ((["&InventorySource&"].MGTACT=Forms.frmMainSearch.MGTACT) Or
(Forms.frmMainSearch.MGTACT) Is Null)"&_
"And ((["&InventorySource&"].ADDINFO=Forms.frmMainSearch.ADDINFO) Or
(Forms.frmMainSearch.ADDINFO) Is Null)"&_
"And ((["&InventorySource&"].BASAL=Forms.frmMainSearch.BASAL) Or
(Forms.frmMainSearch.BASAL) Is Null)"&_
"And ((["&InventorySource&"].DIAM=Forms.frmMainSearch.DIAM) Or
(Forms.frmMainSearch.DIAM) Is Null)"&_
"And ((["&InventorySource&"].REGEN=Forms.frmMainSearch.REGEN) Or
(Forms.frmMainSearch.REGEN) Is Null)"&_
"And ((["&InventorySource&"].EUAGED=Forms.frmMainSearch.EUAGED) Or
(Forms.frmMainSearch.EUAGED) Is Null)"&_
"And ((["&InventorySource&"].MUD=Forms.frmMainSearch.MUD) Or
(Forms.frmMainSearch.MUD) Is Null)"&_
"And ((["&InventorySource&"].METAL=Forms.frmMainSearch.METAL) Or
(Forms.frmMainSearch.METAL) Is Null)"&_
"And ((Forms.frmMainSearch.STARTDATE Is Null) Or
(Forms.frmMainSearch.ENDDATE Is Null)"&_
"Or (["&InventorySource&"].DATE Between Forms.frmMainSearch.STARTDATE
And Forms.frmMainSearch.ENDDATE))"&_
"And ((Forms.frmMainSearch.MINACR Is Null) Or
(Forms.frmMainSearch.MAXACR Is Null)"&_
"Or (["&InventorySource&"].ACREAGE Between Forms.frmMainSearch.MINACR
And Forms.frmMainSearch.MAXACR))"&_
"And ((["&InventorySource&"].UpWet=Forms.frmMainSearch.UPWET) Or
(Forms.frmMainSearch.UPWET Is Null)));"
Thanks in advance for any input.
character and concatenation, I've tried to appease the compiler.
However, I keep getting Expected errors. I think that there are
limitations to SQL strings in VBA i.e. lines and characters. From
reading other posts, I see that multiple occurences of strSQL can be
used too. I've tried coding this string different ways with no luck.
Can someone take a look at this code and help me reformat it properly
so that it doesn't keep giving me compile errors?
I'm pretty sure that I need to break it up so that I have
strSQL="Select * From "
strSQL=strSQL&"Where"
And so on.
Here's my code:
Dim strSQL As String
strsql = "SELECT * FROM "&InventorySource&""&_
"WHERE(((["&InventorySource&"].NRMU_NO_1=Forms.frmMainSearch.NRMU_NO_1)
Or (Forms.frmMainSearch.NRMU_NO_1) Is Null)"&_
"And ((["&InventorySource&"].USETYPE=Forms.frmMainSearch.USETYPE) Or
(Forms.frmMainSearch.USETYPE) Is Null)"&_
"And ((["&InventorySource&"].LANDCOVER=Forms.frmMainSearch.LANDCOVER)
Or (Forms.frmMainSearch.LANDCOVER) Is Null)"&_
"And ((["&InventorySource&"].DOM1=Forms.frmMainSearch.DOM1) Or
(Forms.frmMainSearch.DOM1) Is Null)"&_
"And ((["&InventorySource&"].DOM2=Forms.frmMainSearch.DOM2) Or
(Forms.frmMainSearch.DOM2) Is Null)"&_
"And ((["&InventorySource&"].DOM3=Forms.frmMainSearch.DOM3) Or
(Forms.frmMainSearch.DOM3) Is Null)"&_
"And ((["&InventorySource&"].AGE2SP1=Forms.frmMainSearch.AGE2SP1) Or
(Forms.frmMainSearch.AGE2SP1) Is Null)"&_
"And ((["&InventorySource&"].AGE2SP2=Forms.frmMainSearch.AGE2SP2) Or
(Forms.frmMainSearch.AGE2SP2) Is Null)"&_
"And ((["&InventorySource&"].AGE2SP3=Forms.frmMainSearch.AGE2SP3) Or
(Forms.frmMainSearch.AGE2SP3) Is Null)"&_
"And ((["&InventorySource&"].MGTCON=Forms.frmMainSearch.MGTCON) Or
(Forms.frmMainSearch.MGTCON) Is Null)"&_
"And ((["&InventorySource&"].MGTACT=Forms.frmMainSearch.MGTACT) Or
(Forms.frmMainSearch.MGTACT) Is Null)"&_
"And ((["&InventorySource&"].ADDINFO=Forms.frmMainSearch.ADDINFO) Or
(Forms.frmMainSearch.ADDINFO) Is Null)"&_
"And ((["&InventorySource&"].BASAL=Forms.frmMainSearch.BASAL) Or
(Forms.frmMainSearch.BASAL) Is Null)"&_
"And ((["&InventorySource&"].DIAM=Forms.frmMainSearch.DIAM) Or
(Forms.frmMainSearch.DIAM) Is Null)"&_
"And ((["&InventorySource&"].REGEN=Forms.frmMainSearch.REGEN) Or
(Forms.frmMainSearch.REGEN) Is Null)"&_
"And ((["&InventorySource&"].EUAGED=Forms.frmMainSearch.EUAGED) Or
(Forms.frmMainSearch.EUAGED) Is Null)"&_
"And ((["&InventorySource&"].MUD=Forms.frmMainSearch.MUD) Or
(Forms.frmMainSearch.MUD) Is Null)"&_
"And ((["&InventorySource&"].METAL=Forms.frmMainSearch.METAL) Or
(Forms.frmMainSearch.METAL) Is Null)"&_
"And ((Forms.frmMainSearch.STARTDATE Is Null) Or
(Forms.frmMainSearch.ENDDATE Is Null)"&_
"Or (["&InventorySource&"].DATE Between Forms.frmMainSearch.STARTDATE
And Forms.frmMainSearch.ENDDATE))"&_
"And ((Forms.frmMainSearch.MINACR Is Null) Or
(Forms.frmMainSearch.MAXACR Is Null)"&_
"Or (["&InventorySource&"].ACREAGE Between Forms.frmMainSearch.MINACR
And Forms.frmMainSearch.MAXACR))"&_
"And ((["&InventorySource&"].UpWet=Forms.frmMainSearch.UPWET) Or
(Forms.frmMainSearch.UPWET Is Null)));"
Thanks in advance for any input.