Array Help

G

Guest

Can anyone help with the following code. I think my code is halting on the
myVarArr(k) if the variable type is not compatible. But I dont know how to
fix it. I took it from another macro I wrote previously which works fine.

Bruce

Function saveGeneralPricelists()

Dim b As Variant
Dim myVarArr(1 To 2)
Dim myVar
ReDim myVar(1 To 2)


DoCmd.SetWarnings False

a = "rpt_PL_General"

myVar = Array("F", "R")
myVarArr(1) = Array("Food Service")
myVarArr(2) = Array("Retail")

myCountry = Array(100, 200, 300, 1000, 1100, 1200, 1300, 1500, 1600, 1700)

k = 1
For Each b In myVar

For Each c In myCountry
DoCmd.OpenReport a, acPreview, "", "[PLT_ID]=""" & b & """
And [CountryID]=" & c
DoCmd.OutputTo acReport, "", "SnapshotFormat(*.snp)",
CurrentProject.Path & "\Pricelists\" & myVarArr(k) & "\" & c & ".snp", False,
""
DoCmd.Close acReport, "rpt_PL_General"
DoCmd.SetWarnings True
Next c

k = k + 1
Next b

DoCmd.SetWarnings True

End Function
 
G

Guest

At the top of the module include the lines

Option Compare Database
Option Explicit

and withing your function also declare the following

Dim a As String
Dim myCountry As Variant
Dim k As Integer
Dim c As Variant
 

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