String not passing

tuktuk

Well-known Member
Joined
Nov 13, 2006
Messages
856
why wouldnt the strNetwDesc not be passing thru in the following code?

the data for the strNetwork is correct and is used in an append qry but i'm not able to save the file name using the strNetwDesc.

here is hte skinny.....i have a qry Net list that has an id and a desc....i want to use the id as a parameter for the qry and then the desc for that associate id in the file name.

Code:
Private Sub GenerateReports()

DoCmd.SetWarnings False

Dim rsNetwork As Recordset
Dim X As Integer

Set rsNetwork = CurrentDb.OpenRecordset("qry_Net_List")

Dim flds As DAO.Fields
Dim fld As DAO.Field
Dim strNetwork As String

Set flds = rsNetwork.Fields
Set fld = flds("NETWID")

Dim fldsDesc As DAO.Fields
Dim fldDesc As DAO.Field
Dim strNetworkDesc As String

Set fldsDesc = rsNetwork.Fields
Set fldDesc = fldsDesc("NETDES")


With rsNetwork
    .MoveFirst
    

    
Do While Not .EOF
strNetwork = fld
strNeworkDesc = fldDesc


DoCmd.OpenQuery ("DMA_Delete")

Const QRY_APPEND = "qry_DMA_Append"
Dim db As DAO.Database
Dim qdf As DAO.QueryDef

Set db = CurrentDb
Set qd = db.QueryDefs("qry_DMA_Append")
qd.Parameters(0) = strNetwork
qd.Execute

'save the template as strRegion
                            
Const FILE_PATH As String = "G:\MyPath\CreationTools\"
    Dim FullPath As String
    strFullPath = FILE_PATH
                               
Const FILE_PATH_TWO As String = "G:\MyPath\"
    Dim SavePath As String
    strSavePath = FILE_PATH_TWO

Set objXl = GetObject("Book1").Application
        With objXl.Application
        .Visible = True
        .Workbooks.Open "G:\MyPath\NetworkSummaryTemplate.xls"
        .Worksheets("DMAQuery").Hide
        .Worksheets("DMA Detail").Activate
        objXl.Cells(1, 1).Value = strNetworkDesc
        
        .ActiveWorkbook.SaveAs (strSavePath & "Network Detail for " & strNetworkDesc & ".xls")
        .ActiveWorkbook.Close
        End With

.MoveNext

Loop
DoCmd.SetWarnings True
End With
End Sub
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
What string strNetwDesc?

There isn't a constant or variable with that name.:)
 
Upvote 0
it a field within the "qry_Net_List"....can you use the same recordset?

or do i need to declare a

Code:
Set rsNetworkDesc = CurrentDb.OpenRecordset("qry_Net_List")
 
Upvote 0
opp i wrote it in free text......i'm referrring to "strNeworkDesc".

does that help?

t
 
Upvote 0
I'm not talking about the recordset - you do not seem to have a variable/constant/recordset with that name.

Mind you perhaps I'm missing something, it is quite late here, and Friday night.:)
 
Upvote 0
I think you really need to check your variable/recordset etc names.

One good way to help with that would be to put Option Explicit at the top of the module the code is in.

If you do that then the code won't compile and, hopefully, you'll find any errant variables.

Might just be a typo.:)

PS You can automatically set that option if you goto Tools>Options...

On the General tab check Require Variable Declaration.
 
Upvote 0
hmmm im not sure if i follow. here is what i am attempting to do.

i want to step thru a qry result which has to fields.

i want to use the first field in an append qry as a criteria parmater. then i export the append results to a .xls template.

then using the second field in the name of the save .xls file.

does that help?
tuk
 
Upvote 0

Forum statistics

Threads
1,215,096
Messages
6,123,074
Members
449,093
Latest member
ripvw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top