Solved

Pass a parameter in VBA based on external variable value

Posted on 2007-03-21
5
479 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 120

Expert Comment

by:Rey Obrero (Capricorn1)
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 120

Expert Comment

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

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

680 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