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"
'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