Solved

Pass a parameter in VBA based on external variable value

Posted on 2007-03-21
5
470 Views
Last Modified: 2013-11-25
I have a docmd in VBA that is an append query, but I need to check an external datapoint and depending on that datapoint, the append query should alter the text that is appended to the table.  Am I back to not getting the quotes correct or should the strType be in another format?

If Forms!frmImportMenuFSC.cboForecast = "Budget" Then
    strType = "BUDFSCHSN"
ElseIf Forms!frmImportMenuFSC.cboForecast = "R1" Then
    strType = "R1FSCHSN"
ElseIf Forms!frmImportMenuFSC.cboForecast = "R2" Then
    strType = "R2FSCHSN"
End If


strAppendData = "INSERT INTO tblFSCDetail ( SAP, WorksheetID, ForecastYear, Jan, " & _
    "Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, [Dec] ) " & _
    "SELECT tblTempRetail.SAP," & " ' strType ' " & " AS WorksheetID, " & _
    "FORMS!frmImportMenuFSC.txtForecastYear AS ForecastYear, " & _
    "tblTempRetail.Jan, tblTempRetail.Feb, tblTempRetail.Mar, " & _
    "tblTempRetail.Apr , tblTempRetail.May, tblTempRetail.Jun, " & _
    "tblTempRetail.Jul, tblTempRetail.Aug, tblTempRetail.Sep, " & _
    "tblTempRetail.Oct, tblTempRetail.Nov, tblTempRetail.Dec " & _
    "FROM tblTempRetail "
0
Comment
Question by:ssmith94015
5 Comments
 
LVL 7

Accepted Solution

by:
UniqueData earned 500 total points
ID: 18767316
Instead of:
 "SELECT tblTempRetail.SAP," & " ' strType ' " & " AS WorksheetID, " & _

Try:
 "SELECT tblTempRetail.SAP, '" &  strType   & "' AS WorksheetID, " & _

Michael
0
 
LVL 7

Expert Comment

by:Imoutwest
ID: 18767325
For strType as a string:
>& " ' strType ' " &
should be & "'" & strType & "'" &

0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 18767351
try this

SELECT tblTempRetail.SAP," & strType & " AS WorksheetID, " &
0
 

Author Comment

by:ssmith94015
ID: 18767370
UniqueData, I do not know what you did because I thought I had tried a version of what wrote, but it did not work I just copied your and it works perfectly.  I think I am getting really tired, I had a nap a few days ago.....  Thank you both.
0
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 18767376
nevermind my post, thought you are passing a name of field.....
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now