I have the following code, the first set of code is the SQL version, the second set of code is an attempt to put the code into a VB String see "UpdateVariatio ns". I need help, I think most of it is fine, but the LIKE statement is the problem, I can't figure out how to get the quotes around the like such as '*Sheriff*' Any help would be great. You will notice that I tried putting the sheriff match in a separate string, but decided to try going back to the original. When I tried the Sheriff like as a separate string I inserted " & SheriffAs & ", I think that is correct, but either way, I end up with a popup asking what Sheriff is. I tested to be sure it was the LIKE sheriff that was the issue by adding extra "r"s to the word and sure it enough it asked what Sherrriff is.
Thanks for the review and any help. I am at a complete loss.
Dan
Thanks for the review and any help. I am at a complete loss.
Dan
Code:
UPDATE DGBTestVariations
SET DGBTestVariations.LEA =
IIF(DGBTestVariations.LEA = "DPS","State Patrol",
IIF(DGBTestVariations.LEA = "Sheriff",(DLookup("[LEAName]","CATJusidictionList","[LEAName] Like '*Sheriff*'")),
IIF(DGBTestVariations.LEA = "DNR","DNR",
IIF(DGBTestVariations.LEA = "DOT","DOT",
IIF(DGBTestVariations.LEA = "ANY","ANY",
IIF(DGBTestVariations.LEA IS NULL,"ANY",DGBTestVariations.LEA
)
)
)
)
)
)
,
DGBTestVariations.JURISDICTION =
IIF(DGBTestVariations.JURISDICTION = "NoMoneyMuni", (DLookup("[JurisCodes]","JurisdictionComOfOffense","[JurisGroups]='NoMoneyMuni'")) ,
IIF(DGBTestVariations.JURISDICTION = "Municipalities", (DLookup("[JurisCodes]","JurisdictionComOfOffense","[JurisGroups]='Municipalities'")) ,
IIF(DGBTestVariations.JURISDICTION = "County", (DLookup("[JurisCodes]","JurisdictionComOfOffense","[JurisGroups]='County'")) ,
IIF(DGBTestVariations.JURISDICTION IS NULL, "ANY", DGBTestVariations.JURISDICTION
)
)
)
),
DGBTestVariations.PROSECUTOR =
IIF(DGBTestVariations.PROSECUTOR = "CountyAtty", (DLookup("[AttyCodes]","ProsecutAgencies","[AttyGroups]='CountyAtty'")),
IIF (DGBTestVariations.PROSECUTOR = "CityAtty", (DLookup("[AttyCodes]","ProsecutAgencies","[AttyGroups]='CityAtty'")),
IIF(DGBTestVariations.PROSECUTOR IS NULL,"ANY",DGBTestVariations.PROSECUTOR
)
)
)
Code:
Dim Tabck As String
Dim CreateLEA, InsertToLEA, CreateVariations, DeletePD, UpdateVariations, NoMoneyMuni, CountyAtty, CityAtty, Municipalities, SheriffAs As String
CreateLEA = "CREATE TABLE LEA_NAMES (ID AUTOINCREMENT, LEA_Agency_Name TEXT(50))"
NoMoneyMuni = "NoMoneyMuni"
CountyAtty = "CountyAtty"
CityAtty = "CityAtty"
Municipalities = "Municipalities"
SheriffAs = " '*Sheriff*' "
InsertToLEA = "INSERT INTO LEA_NAMES (LEA_Agency_Name)SELECT LEFT$([LEAName], InStr([LEAName], 'Police') - 1) & ' PD' FROM CATJusidictionList WHERE [LEAName] like '*Police*'"
CreateVariations = "SELECT AAFeeSchedTemplate.ID AS ID, AAFeeSchedTemplate.[Fee Schedule], AAFeeSchedTemplate.LEA.Value AS LEA, AAFeeSchedTemplate.Jurisdiction.Value AS JURISDICTION, AAFeeSchedTemplate.Prosecutor.Value AS PROSECUTOR INTO DGBTestVariations FROM AAFeeSchedTemplate;"
DeletePD = "DELETE FROM DGBTestVariations where LEA = 'MuniPD'"
UpdateVariations = "UPDATE DGBTestVariations SET DGBTestVariations.LEA = " _
& "IIF(DGBTestVariations.LEA = 'DPS','State Patrol'," _
& "IIF(DGBTestVariations.LEA = 'Sheriff',(DLookup('[LEAName]','CATJusidictionList','[LEAName] Like " _
& " '*Sheriff*' " & " ')), " _
& "IIF(DGBTestVariations.LEA = 'DNR','DNR', " _
& "IIF(DGBTestVariations.LEA = 'DOT','DOT', " _
& "IIF(DGBTestVariations.LEA = 'ANY','ANY', " _
& "IIF(DGBTestVariations.LEA IS NULL,'ANY',DGBTestVariations.LEA ))))))," _
& "DGBTestVariations.JURISDICTION = " _
& "IIF(DGBTestVariations.JURISDICTION = 'NoMoneyMuni', (DLookup('[JurisCodes]','JurisdictionComOfOffense','[JurisGroups]=" & NoMoneyMuni & "')) , " _
& "IIF(DGBTestVariations.JURISDICTION = 'Municipalities', (DLookup('[JurisCodes]','JurisdictionComOfOffense','[JurisGroups]=" & Municipalities & "')) , " _
& "IIF(DGBTestVariations.JURISDICTION = 'County', (DLookup('[JurisCodes]','JurisdictionComOfOffense','[JurisGroups]=" & County & "')) , " _
& "IIF(DGBTestVariations.JURISDICTION IS NULL, 'ANY', DGBTestVariations.JURISDICTION )))), " _
& "DGBTestVariations.PROSECUTOR = " _
& "IIF(DGBTestVariations.PROSECUTOR = 'CountyAtty', (DLookup('[AttyCodes]','ProsecutAgencies','[AttyGroups]=" & CountyAtty & "')), " _
& "IIF (DGBTestVariations.PROSECUTOR = 'CityAtty', (DLookup('[AttyCodes]','ProsecutAgencies','[AttyGroups]=" & CityAtty & "')), " _
& "IIF(DGBTestVariations.PROSECUTOR IS NULL,'ANY',DGBTestVariations.PROSECUTOR )))"
Tabck = TableChk("LEA_Names")
MsgBox (Tabck)
DoCmd.RunSQL (CreateLEA)
DoCmd.RunSQL (InsertToLEA)
DoCmd.RunSQL (UpdateVariations)
End Sub
Comment