troubleshooting Question

Assign result of ACCESS 2003 VBA SQL to variable for use in another text box.

Avatar of Sandra Smith
Sandra SmithFlag for United States of America asked on
Microsoft AccessMicrosoft Development
4 Comments1 Solution1103 ViewsLast Modified:
I have the below code in a form module attached to the Afterupdate event.  However, what I need is for the result of the strTEMPSAP query to be assigned to a variable so I can use it in Me.txtTempNumber.  So, how do I get the result into my variable?  This is in an ACCESS 2003 mdb database.

Private Sub cboCountry_AfterUpdate()
'Reviews the tblOpenDates table, based on country, for the maximum
'number in the TempNumber field and assigns the next digit
'to create the next TempNumber for new stores
Dim strTempSAP As String
Dim strCountryCode As String
Dim numNext As Single
Dim numYearOpened As Double

numYearOpened = Year(Me.txtDate)
If Me.cboCountry = "US" Then
    strCountryCode = "US"
ElseIf Me.cboCountry = "CANADA" Then
    strCountryCode = "CAN"
ElseIf Me.cboCountry = "MEXICO" Then
    strCountryCode = "MEX"
End If
'Gets the max TempNumber digits based on the country as inputted in the
'cboCountry combo box and the year opened in the txtYearOpened textbox.
'Tempnumbers are in the format of US2008-01, etc.
strTempSAP = "SELECT FORMAT(Right([MaxOfTempNumber],2)+1, '00') AS NextNo " & _
    "FROM [SELECT tblOpenDates.Country, Max(tblOpenDates.TempNumber) AS MaxOfTempNumber " & _
    "FROM tblOpenDates GROUP BY tblOpenDates.Country " & _
    "HAVING tblOpenDates.Country = " & Me.cboCountry & " AND " & _
    "Not IsNull(Max(tblOpenDates.TempNumber))]. AS [%$##@_Alias] "

Me.txtTempNumber = strCountryCode & numYearOpened & "-" & numNext
End Sub
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros