Dear All,
Might be a stupid question but the value which I assign to a variable in the if-then statement gets lost after 'end if'. Below are 2 examples to illustrate that.
In first example I assign x=1 within if-then statement. Output with Debug.Print is nothing:
Private Sub Command2_Click()
Dim a, x As String
a = [Forms]![F_DB/HIPI5_2]![Combo0]
If a = All Then
x = 1
Debug.Print x
End If
End Sub
In second example I assign x=1 after if-then statement. Output with Debug.Print is '1':
Private Sub Command2_Click()
Dim a, x As String
a = [Forms]![F_DB/HIPI5_2]![Combo0]
If a = All Then
End If
x = 1
Debug.Print x
End Sub
My ultimate goal is to select with a combo box a query which is to be exported. The code was supposed to be the following (there are more options of 'a'):
Private Sub Command2_Click()
Dim a, x As String
Dim db As DAO.Database
Dim b As QueryDef
Set db = Currentdb()
a = [Forms]![F_DB/HIPI5_2]![Combo0]
If a = All Then
Set b = db.QueryDefs("Q_DB/Amounts_Output/CMO")
End If
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, b, "CMO", True
MsgBox ("Export complete")
End Sub
Thank you for help.
Might be a stupid question but the value which I assign to a variable in the if-then statement gets lost after 'end if'. Below are 2 examples to illustrate that.
In first example I assign x=1 within if-then statement. Output with Debug.Print is nothing:
Private Sub Command2_Click()
Dim a, x As String
a = [Forms]![F_DB/HIPI5_2]![Combo0]
If a = All Then
x = 1
Debug.Print x
End If
End Sub
In second example I assign x=1 after if-then statement. Output with Debug.Print is '1':
Private Sub Command2_Click()
Dim a, x As String
a = [Forms]![F_DB/HIPI5_2]![Combo0]
If a = All Then
End If
x = 1
Debug.Print x
End Sub
My ultimate goal is to select with a combo box a query which is to be exported. The code was supposed to be the following (there are more options of 'a'):
Private Sub Command2_Click()
Dim a, x As String
Dim db As DAO.Database
Dim b As QueryDef
Set db = Currentdb()
a = [Forms]![F_DB/HIPI5_2]![Combo0]
If a = All Then
Set b = db.QueryDefs("Q_DB/Amounts_Output/CMO")
End If
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, b, "CMO", True
MsgBox ("Export complete")
End Sub
Thank you for help.