Microsoft
Software
Hardware
Network
Question : How do I store the result of a select query into a variable
I created a simple table with 2 columns as well as a form. I want to grab the user input from a combo box and query the table for the result to be used later. For example, my table looks like
Jan 10 | 013110
Feb 10 | 022810
If the user selects 'Jan 10' in the combo box, I want to store the '013110' in a variable to use later.
The following code executes the query but it opens the results in a datasheet which I do not want to display. Do I need to create a record set for the single value? Here is my code below
Set db = CurrentDb()
Set qdf = db.QueryDefs("qryBatchHead
er")
strSql = "Select tblBatchHeader.MonthValue from tblBatchHeader where tblBatchHeader.MonthName = Forms![frmUserform]![Month
];"
qdf.SQL = strSql
Me.Visible = False
DoCmd.OpenQuery "qryBatchHeader", acViewNormal, acEdit
DoCmd.Close acForm, "frmUserform"
Thank you in advance!
Audrey
Answer : How do I store the result of a select query into a variable
try this, there is an extra '
copy this and paste
Dim myVariable
myVariable = DLookup("MonthValue", "tblBatchHeader", "MonthName='" & Forms![frmUserform]![Month
] & "'")
MsgBox myVariable
Random Solutions
Reservation Database, need help with organization, etc.
Visual Studio 2008 C# XNA - Creating a timer sequence for updated objects
%*PNPB01B.DeviceDesc% Conflict
Attachments to GroupWise
Datagridviewcombobox ondrawitem works but has over 30 items in dropdown..
how to round $elling price to nearest fifty cents
Difficulty uploading items larger than 1 MB
Simple Automation with Infopath 2003 and SPS 3.0 - Calculate Directory / Filename to save as
Connect to an XP PC with Windows 7
MFC7 CDHtmlDialog: How to cancel a navigation in OnBeforeNavigate