Flexible Like in access 2007 - ms-access-2007

I have this code. But I can not get it anything.
SMain_EW = RS.Fields("Main_EW").Value
Dim MyCheck
If SMain_EW Like "*" & Me.Text0 & "*" = True Then
MsgBox "1"
End If
Edited:********************
I edited as bellow:
Do Until RS.EOF
SMainEW = RS.Fields("Main_EW").Value
ST_EW_1 = RS.Fields("T_EW_1").Value
If SMainEW Like "*" & Me.Text0 & "*" Then
strItem1 = "*" & RS.Fields("Main_EW").Value
strItem2 = RS.Fields("T_EW_1").Value
ElseIf ST_EW_1 Like "*" & Me.Text0 & "*" Then
strItem2 = "*" & RS.Fields("T_EW_1").Value
strItem1 = RS.Fields("Main_EW").Value
Else
strItem2 = RS.Fields("T_EW_1").Value
strItem1 = RS.Fields("Main_EW").Value
End If
strItem = strItem1 & ";" _
& strItem2
Me.List122.AddItem strItem
RS.MoveNext
Loop

Try removing the "= True" portion, it's redundant. It should just read:
SMain_EW = RS.Fields("Main_EW").Value
Dim MyCheck
If SMain_EW Like "*" & Me.Text0 & "*" Then
MsgBox "1"
End If

Related

Using the Like "*" operator in a If Statement

I am trying to create a filter based on four combo boxes that filter records in a subform. The problem is, one value from the RowSource lists on the combo boxes do not exist in the base query.
That value is "All". I was planning to use the same code on all the combo boxes AfterUpdate event. Please see my approach below and advice where necessary. I currently get a type mismatch error on the Me.Combobox1.Value = "Like "*""
If IsNull(Me.combo1.Value) Or IsNull(Me.combo2.Value) Or IsNull(Me.combo3.Value) Or
IsNull(Me.combo4.Value) Then
Exit Sub
End If
If Not IsNull(Me.combo1.Value) Or Not IsNull(combo2.Value) Or Not IsNull(combo3.Value) Or Not
IsNull(combo4.Value) Then
If Me.combo1 = "All" Then
Me.combo1.Value = "Like " * ""
ElseIf Me.combo2.Value = "All" Then
Me.combo2.Value = "Like " * ""
ElseIf Me.combo3.Value = "All" Then
Me.combo3.Value = "Like " * ""
ElseIf Me.combo4.Value = "All" Then
Me.combo4.Value = "Like " * ""
Task1 = "SELECT * FROM qryBase WHERE [Quarter] = '" & Me.combo1.Value & "' AND [CurrentArea] = '" &
Me.combo2.Value & "' AND [CurrentStatus] = '" & Me.combo3.Value & "' AND [MainUser] = '" &
Me.combo4.Value & "'"
End If
End If
As is, your query cannot work as LIKE is meant to replace = in conditional statements. However, LIKE without wildcards behaves like =. Therefore, place the LIKE operator inside the SQL statement.
Dim cbo1, cbo2, cbo3, cbo4 As String
...
If Me.combo1 = "All" Then
cbo1 = "*"
ElseIf Me.combo2.Value = "All" Then
cbo2 = "*"
ElseIf Me.combo3.Value = "All" Then
cbo3 = "*"
ElseIf Me.combo4.Value = "All" Then
cbo4 = "*"
End If
Task1 = "SELECT * FROM qryBase WHERE [Quarter] LIKE '" & cbo1 & "'" _
& " AND [CurrentArea] LIKE '" & cbo2 & "'" _
& " AND [CurrentStatus] LIKE '" & cbo3 & "'" _
& " AND [MainUser] LIKE '" & cbo4 & "'"
Me.frmDatasheet.Form.Recordsource = Task1
Me.frmDatasheet.Form.Requery
However, because combo boxes can have apostrophes, consider parameterization to avoid need of concatenating VBA values directly into SQL but bind them as parameters:
Dim qdef As QueryDef
Dim rst As Recordset
Dim sql AS String
Dim cbo1, cbo2, cbo3, cbo4 As String
sql = "PARAMETERS cbo1 TEXT, cbo2 TEXT, cbo3 TEXT, cbo4 TEXT;" _
& "SELECT * FROM qryBase WHERE [Quarter] LIKE [cbo1]" _
& " AND [CurrentArea] LIKE [cbo2]" _
& " AND [CurrentStatus] LIKE [cbo3]" _
& " AND [MainUser] LIKE [cbo4]"
If Me.combo1 = "All" Then
cbo1 = "*"
ElseIf Me.combo2.Value = "All" Then
cbo2 = "*"
ElseIf Me.combo3.Value = "All" Then
cbo3 = "*"
ElseIf Me.combo4.Value = "All" Then
cbo4 = "*"
End If
' INITIALIZE QUERY OBJECT
Set qdef = CurrentDb.CreateQueryDef("", sql)
' Set qdef = CurrentDb.QueryDefs("mySavedParamQuery")
' BIND PARAMS
qdef!cbo1 = cbo1
qdef!cbo2 = cbo2
qdef!cbo3 = cbo3
qdef!cbo4 = cbo4
' SET FORM RECORDSET TO EXECUTED QUERY
Set rst = qdef.OpenRecordset()
Set Me.frmDatasheet.Form.Recordset = rst
Set rst = Nothing: Set qdef = Nothing

MS Access if statement on click event

I am using Ms Access forms and I have created an on click event that locates a folder location but now I want to locate the folder location based on different criteria but when I add the if statement it expects a sub,function or property. Below is some demo code. I really hope someone can explain what is missing?
Private Sub Open_Email_Click()
Dim stAppName As String
Dim stAppNameA As String
Dim stAppNameB As String
stAppName = "C:\Windows\explorer.exe C:\DEMO\TEST\" & Me.Office & " DEMO\B " & Me.BC & " " & Me.UC & "\"
stAppNameA = "C:\Windows\explorer.exe C:\DEMO\TEST\" & Me.Office & " DEMO\A\B " & Me.BC & " " & Me.UC & "\"
stAppNameB = "C:\Windows\explorer.exe C:\DEMO\TEST\" & Me.Office & " DEMO\B\B " & Me.BC & " " & Me.UC & "\"
If (Me.BC = "60") And Me.UC Like "REF123*" Then stAppNameA
ElseIf (Me.BC = "60") And Not Me.UC Like "REF123*" Then stAppNameB
Else: stAppName
End If
Call Shell(stAppName, 1)
End Sub
I think the logic of your function could be reduced to the following, which may be more readable with fewer repeating expressions:
Private Sub Open_Email_Click()
Dim strTmp As String
If Me.BC = "60" Then
If Me.UC Like "REF123*" Then
strTmp = " DEMO\A\B "
Else
strTmp = " DEMO\B\B "
End If
Else
strTmp = " DEMO\B "
End If
Call Shell("C:\Windows\explorer.exe C:\DEMO\TEST\" & Me.Office & strTmp & Me.BC & " " & Me.UC & "\", 1)
End Sub
Alternatively, using a Select Case statement:
Private Sub Open_Email_Click()
Dim strTmp As String
Select Case True
Case Me.BC <> "60"
strTmp = " DEMO\B "
Case Me.UC Like "REF123*"
strTmp = " DEMO\A\B "
Case Else
strTmp = " DEMO\B\B "
End Select
Call Shell("C:\Windows\explorer.exe C:\DEMO\TEST\" & Me.Office & strTmp & Me.BC & " " & Me.UC & "\", 1)
End Sub
To test the resulting path, change:
Call Shell("C:\Windows\explorer.exe C:\DEMO\TEST\" & Me.Office & strTmp & Me.BC & " " & Me.UC & "\", 1)
To:
Debug.Print "C:\Windows\explorer.exe C:\DEMO\TEST\" & Me.Office & strTmp & Me.BC & " " & Me.UC & "\"
I think your If block is just a bit messy in terms of where you have newlines, and continuation characters (:). Try reformatting your code like this:
If (Me.BC = "60") And Me.UC Like "REF123*" Then
stAppName =stAppNameA
ElseIf (Me.BC = "60") And Not Me.UC Like "REF123*" Then
stAppName = stAppNameB
Else
stAppName =stAppName
End If
Call Shell(stAppName, 1)

Unable to Filter

I am trying to write an SQL code in my MS Access database whereby the filter on Entity_name is not working properly
Function FilterResults()
Dim strCriteria As String
strCriteria = ""
If Nz(Me.cboEntitynameFilter) <> "" Then
strEntityNameFilter = "Entity_Name = '" & Me.cboEntitynameFilter & "'"
Else
strEntityNameFilter = "Entity_Name = '*'"
End If
If Nz(Me.cboAssignmentFilter) <> "" Then
strAssignmentFilter = " AND " & "Assignment = '" & Me.cboAssignmentFilter & "'" '& " AND "
End If
If Nz(Me.cboFYFilter) <> "" Then
strFYFilter = " AND " & "Financial_Year = '" & Me.cboFYFilter & "'"
End If
strCriteria = Nz(strEntityNameFilter, "*") & Nz(strAssignmentFilter, "*") & Nz(strFYFilter, "*")
' End If
If strCriteria = ("Entity_Name = '*'") Then
Me.Filter = ""
Me.FilterOn = False
Else
If strCriteria <> "" Then
Me.Filter = strCriteria
Me.FilterOn = True
End If
End If
End Function
The strCriteria returned is
Entity_Name = '*' AND Assignment = 'MFI'
The filter doesn't work and the Entity_Name is all blank. What am I doing wrong.
I am using this in MS-Access and building query in VBA
I would do like this
Dim strCriteria AS string
strCriteria = "1 = 1"
If Len(Nz(Me.cboEntitynameFilter, "")) > 0 Then
strCriteria = strCriteria & " and [Entity_Name] = """ & Me.cboEntitynameFilter & """"
End If
If Len(Nz(Me.cboAssignmentFilter, "")) > 0 Then
strCriteria = strCriteria & " and [Assignment] = """ & Me.cboAssignmentFilter & """"
End If
If Len(Nz(Me.cboFYFilter, "")) > 0 Then
strCriteria = strCriteria & " and [Financial_Year] = """ & Me.cboFYFilter & """"
End If
Me.Filter = strCriteria
Me.FilterOn = True
if any of the combobox or textbox didn't select than it will igonre those field.

How to dynamically add Checkbox-Buttons to userform in VBA

I have a userform with 5 checkbox buttons for 5 pdf versions.
Well, when the user calls the userform, then the userform initializes 5 checkbox buttons to select one of them. At the moment, the code is very static and not so good.
Here the example:
If rs.EOF = False Then
Do Until rs.EOF Or i = 5
Select Case i
Case Is = 0
frmOne.Version5.Visible = True
frmOne.Version5.Caption = rs!versNo & "#" & rs!versFrom
frmOne.Version5.tag = rs!versNo & "_" & rs!FiD & ".pdf"
Case Is = 1
frmOne.Version4.Visible = True
frmOne.Version4.Caption = rs!versNo & "#" & rs!versFrom
frmOne.Version4.tag = rs!versNo & "_" & rs!FiD & ".pdf"
Case Is = 2
frmOne.Version3.Visible = True
frmOne.Version3.Caption = rs!versNo & "#" & rs!versFrom
frmOne.Version3.tag = rs!versNo & "_" & rs!FiD & ".pdf"
Case Is = 3
frmOne.Version2.Visible = True
frmOne.Version2.Caption = rs!versNo & "#" & rs!versFrom
frmOne.Version2.tag = rs!versNo & "_" & rs!FiD & ".pdf"
Case Is = 4
frmOne.Version1.Visible = True
frmOne.Version1.Caption = rs!versNo & "#" & rs!versFrom
frmOne.Version1.tag = rs!versNo & "_" & rs!FiD & ".pdf"
End Select
i = i + 1
rs.MoveNext
Loop
End If
To much code I think. So my intention was to define it like the example below, but this doesn't work:
If rs.EOF = False Then
For i = 1 To 5
With frmOne
.Version & i &.Visible = True
.Version & i &.Caption = rs!versNo & "#" & rs!versFrom
.Version & i &.tag = rs!versNo & "_" & rs!FiD & ".pdf"
End With
rs.MoveNext
Next i
End If
Do have anyone an idea how could I fix that?
You can refer to the Controls collection using the name:
If rs.EOF = False Then
For i = 1 To 5
With frmOne.Controls("Version" & i)
.Visible = True
.Caption = rs!versNo & "#" & rs!versFrom
.tag = rs!versNo & "_" & rs!FiD & ".pdf"
End With
rs.MoveNext
Next i
End If
To actually add the controls at runtime too:
Do While not rs.EOF
i = i + 1
With frmOne.Controls.Add("Forms.CheckBox.1", "Version" & i, True)
.Caption = rs!versNo & "#" & rs!versFrom
.tag = rs!versNo & "_" & rs!FiD & ".pdf"
End With
rs.MoveNext
Loop
go like follows:
If rs.EOF = False Then
For i = 1 To 5
With frmOne.Controls("Version" & i) '<~~ use Controls collection of Userform object
.Visible = True
.Caption = rs!versNo & "#" & rs!versFrom
.Tag = rs!versNo & "_" & rs!FiD & ".pdf"
End With
rs.MoveNext
Next i
End If

Output doesn't match input

I've created a macro that's meant to created a lump of CSS & HTML from a set of values in each sheet of a spreadsheet.
It's a little untidy as I created the function to write it from one sheet first as a proof of concept, and then updated it.
It doesn't throw any obvious errors, but the output varies, sometimes it shows the same thing both times, and then depending on where I've got debug MsgBoxs or watches in VBA seems to alter the output.
Any ideas what on earth i'm doing wrong?
Sub createCode()
Dim myWorkbook As Workbook
Dim mySheet As Worksheet
Set myWorkbook = Application.ActiveWorkbook
For Each mySheet In myWorkbook.Worksheets
Dim bannerCount As Integer
Dim BannerCollection() As Banner
Dim r As Range
Dim lastRow, lastCol
Dim allCells As Range
bannerCount = 0
lastCol = mySheet.Range("a2").End(xlToRight).Column
lastRow = mySheet.Range("a2").End(xlDown).Row
Set allCells = mySheet.Range("a2", mySheet.Cells(lastRow, lastCol))
' MsgBox (mySheet.Name)
' MsgBox ("lastRow:" & lastRow & "lastCol:" & lastCol)
ReDim BannerCollection(allCells.Rows.Count)
For Each r In allCells.Rows
Dim thisBanner As Banner
thisBanner.imagePath = ""
thisBanner.retImagePath = ""
thisBanner.bannerTitle = ""
thisBanner.urlPath = ""
bannerCount = bannerCount + 1
' MsgBox (bannerCount)
thisBanner.imagePath = Cells(r.Row, 2).Value
thisBanner.retImagePath = Cells(r.Row, 3).Value
thisBanner.bannerTitle = Cells(r.Row, 4).Value
thisBanner.urlPath = Cells(r.Row, 5).Value
'MsgBox (Cells(r.Row, 2).Value)
'MsgBox (Cells(r.Row, 3).Value)
'MsgBox (Cells(r.Row, 4).Value)
'MsgBox (Cells(r.Row, 5).Value)
BannerCollection(bannerCount - 1) = thisBanner
Next r
Dim i As Variant
Dim retinaCSS, imgCSS, firstBannerCode, otherBannersCode, bannerTracking As String
retinaCSS = ""
imgCSS = ""
firstBannerCode = ""
otherBannersCode = ""
bannerTracking = ""
For i = 0 To bannerCount - 1
bannerTracking = BannerCollection(i).bannerTitle
bannerTracking = Replace(bannerTracking, " ", "+")
bannerTracking = Replace(bannerTracking, "&", "And")
bannerTracking = Replace(bannerTracking, "%", "PC")
bannerTracking = Replace(bannerTracking, "!", "")
bannerTracking = Replace(bannerTracking, "£", "")
bannerTracking = Replace(bannerTracking, ",", "")
bannerTracking = Replace(bannerTracking, "'", "")
bannerTracking = Replace(bannerTracking, "#", "")
bannerTracking = Replace(bannerTracking, ".", "")
retinaCSS = retinaCSS & "#sliderTarget .banner-" & i + 1 & "{background-image: url('/assets/static/" & BannerCollection(i).retImagePath & "');}" & vbNewLine
imgCSS = imgCSS & "#sliderTarget .banner-" & i + 1 & "{background-image: url('/assets/static/" & BannerCollection(i).imagePath & "');}" & vbNewLine
If i = 0 Then
firstBannerCode = firstBannerCode & "<div class=" & Chr(34) & "banner banner-" & i + 1 & " staticBanner" & Chr(34) & ">" & vbNewLine
firstBannerCode = firstBannerCode & "" & vbNewLine
firstBannerCode = firstBannerCode & "</div>" & vbNewLine
Else
otherBannersCode = otherBannersCode & "<div class=" & Chr(34) & "banner banner-" & i + 1 & " staticBanner" & Chr(34) & ">" & vbNewLine
otherBannersCode = otherBannersCode & "" & vbNewLine
otherBannersCode = otherBannersCode & "</div>" & vbNewLine
End If
' MsgBox (BannerCollection(i).retImagePath & vbNewLine & BannerCollection(i).imagePath & vbNewLine & BannerCollection(i).bannerTitle & vbNewLine & BannerCollection(i).urlPath)
Next i
CodeString = ""
CodeString = CodeString & "<style type=" & Chr(34) & "text/css" & Chr(34) & ">" & vbNewLine
CodeString = CodeString & "/* Banners */" & vbNewLine
CodeString = CodeString & imgCSS
CodeString = CodeString & "/* Retina Banners */" & vbNewLine
CodeString = CodeString & "#media only screen and (-webkit-min-device-pixel-ratio: 2) {" & vbNewLine
CodeString = CodeString & retinaCSS
CodeString = CodeString & "}" & vbNewLine
CodeString = CodeString & "</style>" & vbNewLine
CodeString = CodeString & "<div id=" & Chr(34) & "sliderTarget" & Chr(34) & " class=" & Chr(34) & "slides" & Chr(34) & ">" & vbNewLine
CodeString = CodeString & firstBannerCode
CodeString = CodeString & "</div>" & vbNewLine
CodeString = CodeString & "<script id=" & Chr(34) & "sliderTemplate" & Chr(34) & " type=" & Chr(34) & "text/template" & Chr(34) & ">" & vbNewLine
CodeString = CodeString & otherBannersCode
CodeString = CodeString & "</script>"
FilePath = Application.DefaultFilePath & "\" & mySheet.Name & "code.txt"
Open FilePath For Output As #2
Print #2, CodeString
Close #2
MsgBox ("code.txt contains:" & CodeString)
MsgBox (Application.DefaultFilePath & "\" & mySheet.Name & "code.txt")
Erase BannerCollection
Next mySheet
End Sub
and here is the Banner type:
Public Type Banner
imagePath As String
retImagePath As String
urlPath As String
bannerTitle As String
End Type
I ended up doing a bit of a code review (oops spent too much time on the Code Review site). I'll post this here in addition to #Jeeped answer in case you get some value from it.
Option Explicit
You should specify Option Explicit at the top of each code module. What this does is tell the VBA compiler to check that every variable that you are trying to use has been declared (i.e. you've got Dim blah as String, Public blah as String or Private blah as String for each blah you're using).
If you attempt to use a variable which hasn't been declared, the compiler will give you a compilation error where the first problem occurs. This helps if you mistype a variable name, otherwise the compiler will think you are talking about something new.
Adding this to the top of your code requires a couple of declarations in your code but nothing major.
Multiple variable declaration on a single line
Don't do it. You have the following line: Dim retinaCSS, imgCSS, firstBannerCode, otherBannersCode, bannerTracking As String which declares 5 variables. The first 4 are declared as variants and the last one is a String. Now your code may work like this but you were probably expecting all 5 to be Strings. Other languages I believe do operate this way but VBA doesn't.
Declare them separately like:
Dim retinaCSS As String
Dim imgCSS As String
Dim firstBannerCode As String
Dim otherBannersCode As String
Dim bannerTracking As String
Don't initialise variables unnecessarily
I see code like:
CodeString = ""
CodeString = CodeString & "<style type=" & Chr(34) & "text/css" & Chr(34) & ">" & vbNewLine
Now the problem with this is that you're assigning the empty string value to CodeString but then you are immediately assigning something else to it in the very next line. The risk is that you might try to use a variable before you have assigned something to it. This isn't a risk for the string type since it implicitly assigned an empty string value when it is created.
You can safely remove the first assignment to it. The danger could come from object references. Say if you have a reference to a worksheet but do not assign a worksheet to the variable before you try to use it. In any case you want to make sure that your variable has the required value before you attempt to use the value it holds.
Use Collection instead of an array
The array code is cumbersome and inflexible. VBA has a simple collection type which allows you to add and remove items to and from it without having to declare a fixed size.
You can also iterate through the contents using a For Each loop.
Here is the code I'm recommending:
Dim BannerCollection As Collection
Set BannerCollection = New Collection
' ...
For Each r In allCells.Rows
Dim thisBanner As Banner
Set thisBanner = New Banner
' ...
BannerCollection.Add thisBanner
Next r
' ...
Dim b As Banner
For Each b In BannerCollection
' do something with the banner.
Next
Now to do this, Banner must be a Class not a Type. I think it makes life a lot easier though.
Split a big method up into single purpose methods.
For instance I extracted a method as follows:
Private Function UrlEncode(ByVal text As String) As String
text = Replace(text, " ", "+")
text = Replace(text, "&", "And")
text = Replace(text, "%", "PC")
text = Replace(text, "!", "")
text = Replace(text, "£", "")
text = Replace(text, ",", "")
text = Replace(text, "'", "")
text = Replace(text, "#", "")
text = Replace(text, ".", "")
UrlEncode = text
End Function
Now this can be referenced like bannerTracking = UrlEncode(b.bannerTitle).
You are setting allCells to a distinct range of cells correctly.
Set allCells = mySheet.Range("a2", mySheet.Cells(lastRow, lastCol))
Then you loop through each row in the allCells range.
For Each r In allCells.Rows
But when you actually go to use r, it is only to use the row number.
thisBanner.imagePath = Cells(r.Row, 2).Value
r.Row is a number between 1 and 1,048,576, nothing more. There is no guarantee that Cells(r.Row, 2).Value refers to something on mySheet; only that whatever worksheet it is coming from it will using whatever worksheet's row number that corresponds to r.row. You need to define some parentage. An With ... End With block within the For ... Next and properly annotated .Range and .Cell references should suffice.
Sub createCode()
Dim myWorkbook As Workbook
Dim mySheet As Worksheet
Dim bannerCount As Integer
Dim BannerCollection() As Banner
Dim r As Range
Dim lastRow, lastCol
Dim allCells As Range
Set myWorkbook = Application.ActiveWorkbook
For Each mySheet In myWorkbook.Worksheets
With mySheet
'declare your vars outside the loop and zero/null then here if necessary.
bannerCount = 0
lastCol = .Range("a2").End(xlToRight).Column
lastRow = .Range("a2").End(xlDown).Row
Set allCells = .Range("a2", .Cells(lastRow, lastCol))
' MsgBox (mySheet.Name)
' MsgBox ("lastRow:" & lastRow & "lastCol:" & lastCol)
ReDim BannerCollection(allCells.Rows.Count)
For Each r In allCells.Rows
Dim thisBanner As Banner
thisBanner.imagePath = ""
thisBanner.retImagePath = ""
thisBanner.bannerTitle = ""
thisBanner.urlPath = ""
bannerCount = bannerCount + 1
' MsgBox (bannerCount)
thisBanner.imagePath = .Cells(r.Row, 2).Value
thisBanner.retImagePath = .Cells(r.Row, 3).Value
thisBanner.bannerTitle = .Cells(r.Row, 4).Value
thisBanner.urlPath = .Cells(r.Row, 5).Value
'MsgBox (.Cells(r.Row, 2).Value)
'MsgBox (.Cells(r.Row, 3).Value)
'MsgBox (.Cells(r.Row, 4).Value)
'MsgBox (.Cells(r.Row, 5).Value)
BannerCollection(bannerCount - 1) = thisBanner
Next r
Dim i As Variant
Dim retinaCSS, imgCSS, firstBannerCode, otherBannersCode, bannerTracking As String
retinaCSS = ""
imgCSS = ""
firstBannerCode = ""
otherBannersCode = ""
bannerTracking = ""
For i = 0 To bannerCount - 1
bannerTracking = BannerCollection(i).bannerTitle
bannerTracking = Replace(bannerTracking, " ", "+")
bannerTracking = Replace(bannerTracking, "&", "And")
bannerTracking = Replace(bannerTracking, "%", "PC")
bannerTracking = Replace(bannerTracking, "!", "")
bannerTracking = Replace(bannerTracking, "£", "")
bannerTracking = Replace(bannerTracking, ",", "")
bannerTracking = Replace(bannerTracking, "'", "")
bannerTracking = Replace(bannerTracking, "#", "")
bannerTracking = Replace(bannerTracking, ".", "")
retinaCSS = retinaCSS & "#sliderTarget .banner-" & i + 1 & "{background-image: url('/assets/static/" & BannerCollection(i).retImagePath & "');}" & vbNewLine
imgCSS = imgCSS & "#sliderTarget .banner-" & i + 1 & "{background-image: url('/assets/static/" & BannerCollection(i).imagePath & "');}" & vbNewLine
If i = 0 Then
firstBannerCode = firstBannerCode & "<div class=" & Chr(34) & "banner banner-" & i + 1 & " staticBanner" & Chr(34) & ">" & vbNewLine
firstBannerCode = firstBannerCode & "" & vbNewLine
firstBannerCode = firstBannerCode & "</div>" & vbNewLine
Else
otherBannersCode = otherBannersCode & "<div class=" & Chr(34) & "banner banner-" & i + 1 & " staticBanner" & Chr(34) & ">" & vbNewLine
otherBannersCode = otherBannersCode & "" & vbNewLine
otherBannersCode = otherBannersCode & "</div>" & vbNewLine
End If
' MsgBox (BannerCollection(i).retImagePath & vbNewLine & BannerCollection(i).imagePath & vbNewLine & BannerCollection(i).bannerTitle & vbNewLine & BannerCollection(i).urlPath)
Next i
CodeString = ""
CodeString = CodeString & "<style type=" & Chr(34) & "text/css" & Chr(34) & ">" & vbNewLine
CodeString = CodeString & "/* Banners */" & vbNewLine
CodeString = CodeString & imgCSS
CodeString = CodeString & "/* Retina Banners */" & vbNewLine
CodeString = CodeString & "#media only screen and (-webkit-min-device-pixel-ratio: 2) {" & vbNewLine
CodeString = CodeString & retinaCSS
CodeString = CodeString & "}" & vbNewLine
CodeString = CodeString & "</style>" & vbNewLine
CodeString = CodeString & "<div id=" & Chr(34) & "sliderTarget" & Chr(34) & " class=" & Chr(34) & "slides" & Chr(34) & ">" & vbNewLine
CodeString = CodeString & firstBannerCode
CodeString = CodeString & "</div>" & vbNewLine
CodeString = CodeString & "<script id=" & Chr(34) & "sliderTemplate" & Chr(34) & " type=" & Chr(34) & "text/template" & Chr(34) & ">" & vbNewLine
CodeString = CodeString & otherBannersCode
CodeString = CodeString & "</script>"
FilePath = Application.DefaultFilePath & "\" & mySheet.Name & "code.txt"
Open FilePath For Output As #2
Print #2, CodeString
Close #2
MsgBox ("code.txt contains:" & CodeString)
MsgBox (Application.DefaultFilePath & "\" & mySheet.Name & "code.txt")
Erase BannerCollection
End With
Next mySheet
End Sub