mostafanabilemostafa
New Member
- Joined
- Feb 11, 2021
- Messages
- 7
- Office Version
- 2016
- Platform
- Windows
I need to use vbquestion 4 times as below
1. The first one asks if you need to upload the first file or not
2. Then asks for the second file
3. Then asks for the third file
4. Then asks for the fourth file
5. Lastly shows a message for the selected files using a string variabe if the file was the correct one it its value is set to Selected if not it is selected to Skipped, then these global variables are called lastly in the last message
i used this code and it works fine
Dim UploadedP As String
Dim UploadedR As String
Dim UploadedM As String
Dim UploadedV As String
Sub Assistant_Mode_Raw()
If MsgBox("Do You Have a raw file to be uploaded?", _
vbQuestion + vbYesNo, "Checking Raw File Existance") = vbYes Then
Z_Import_Raw_SIMs_2 'Calling another module code by its name
UploadedR = "Selected"
Assistant_Mode_Package
Else
UploadedR = "Skipped"
Assistant_Mode_Package
End If
End Sub
Sub Assistant_Mode_Package()
If MsgBox("Do You Have a Package Query file to be uploaded?", _
vbQuestion + vbYesNo, "Checking Package Query File Existance") = vbYes Then
Z_Import_Package_SIMs_2 'Calling another module code by its name
UploadedP = "Selected"
Assistant_Mode_Mobile
Else
UploadedP = "Skipped"
Assistant_Mode_Mobile
End If
End Sub
Sub Assistant_Mode_Mobile()
If MsgBox("Do You Have a Mobile Terminals Query file to be uploaded?", _
vbQuestion + vbYesNo, "Checking Mobile Terminals Query File Existance") = vbYes Then
Z_Import_Mobile_2 'Calling another module code by its name
UploadedM = "Selected"
Assistant_Mode_Vouchers
Else
UploadedM = "Skipped"
Assistant_Mode_Vouchers
End If
End Sub
Sub Assistant_Mode_Vouchers()
If MsgBox("Do You Have a Vocuher Query file to be uploaded?", _
vbQuestion + vbYesNo, "Checking Vocuher Query File Existance") = vbYes Then
Z_Import_Voucher_2 'Calling another module code by its name
UploadedV = "Selected"
Final_step
Else
UploadedV = "Skipped"
Final_step
End If
End Sub
Sub Final_step()
MsgBox "You have selected below BSS Files!" & vbNewLine & vbNewLine & " 1. SIM Card Query File : " & UploadedR & vbNewLine & " 2. Package Query File : " & UploadedP & vbNewLine & " 3. Mobile Terminals Query File : " & UploadedM & vbNewLine & " 4. Vouchers Query File : " & UploadedV & vbNewLine & vbNewLine & "Now Go To Generation Step!", Title:="Assistant Mode Process Notification!"
End Sub
up to this point everything goes ok. but i added some validation process in which let the uploaded file to be validated if it is correct one or not.
This validation process exists in the external called sub For improting the file for Ex (Z_Import_Raw_SIMs_2).
and so on for every file of the 4 file types of the 4 questions.
So to discuss the issue and make it more clear
lets assume that we run the code and will go through the 4 questions
If we clicked yes that we have the file then import function is called here the rule of validations comes
IF the file was incorrectly choosen another message asks if you still have the file if we clicked yes and chose the right file this time
the 2nd questions comes if we clicked no and the same for the 2 remaining questions
the Expected result is to end processing after the final pop up message of Final_step () that telling us the selected files and the skipped ones
but the problem comes here then due to the first incorrectly chossen file.
as instead of end processing
it asks again for the non selected if we still need to import them or not
While trying to debug i found that
After perfoming the last command of Final_step () , it comes to the 3rd question to pass by end if then pass by its end sub and do the same for the 2nd question and the first one
then suddenly the debug curser moves to
EndIF
of the validation part
'First Validation for uploaded file using File Name
If InStr(OpenBookR2.Name, "Voucher") > 0 Or InStr(OpenBookR2.Name, "Mobile") Or InStr(OpenBookR2.Name, "Package") Then
SaveChanges = False
OpenBookR2.Close
MsgBox "You have not Chosen the right BSS File!" & vbNewLine & vbNewLine & "Please choose the right BSS RAW SIM File", Title:="Wrong Processing Notification!"
Assistant_Mode_Raw
End If
which is part of the import function like below
FileToOpenR2 = Application.GetOpenFilename(Title:="Browse for Raw SIMs File & Upload it", FileFilter:="Excel Files (*.xls*),*xls*")
If FileToOpenR2 <> False Then
Set OpenBookR2 = Application.Workbooks.Open(FileToOpenR2)
Set Rsheet2 = OpenBookR2.Worksheets("Default")
'First Validation for uploaded file using File Name
If InStr(OpenBookR2.Name, "Voucher") > 0 Or InStr(OpenBookR2.Name, "Mobile") Or InStr(OpenBookR2.Name, "Package") Then
SaveChanges = False
OpenBookR2.Close
MsgBox "You have not Chosen the right BSS File!" & vbNewLine & vbNewLine & "Please choose the right BSS RAW SIM File", Title:="Wrong Processing Notification!"
Assistant_Mode_Raw
End If
so any recommdantion to fix this looped IF
1. The first one asks if you need to upload the first file or not
2. Then asks for the second file
3. Then asks for the third file
4. Then asks for the fourth file
5. Lastly shows a message for the selected files using a string variabe if the file was the correct one it its value is set to Selected if not it is selected to Skipped, then these global variables are called lastly in the last message
i used this code and it works fine
Dim UploadedP As String
Dim UploadedR As String
Dim UploadedM As String
Dim UploadedV As String
Sub Assistant_Mode_Raw()
If MsgBox("Do You Have a raw file to be uploaded?", _
vbQuestion + vbYesNo, "Checking Raw File Existance") = vbYes Then
Z_Import_Raw_SIMs_2 'Calling another module code by its name
UploadedR = "Selected"
Assistant_Mode_Package
Else
UploadedR = "Skipped"
Assistant_Mode_Package
End If
End Sub
Sub Assistant_Mode_Package()
If MsgBox("Do You Have a Package Query file to be uploaded?", _
vbQuestion + vbYesNo, "Checking Package Query File Existance") = vbYes Then
Z_Import_Package_SIMs_2 'Calling another module code by its name
UploadedP = "Selected"
Assistant_Mode_Mobile
Else
UploadedP = "Skipped"
Assistant_Mode_Mobile
End If
End Sub
Sub Assistant_Mode_Mobile()
If MsgBox("Do You Have a Mobile Terminals Query file to be uploaded?", _
vbQuestion + vbYesNo, "Checking Mobile Terminals Query File Existance") = vbYes Then
Z_Import_Mobile_2 'Calling another module code by its name
UploadedM = "Selected"
Assistant_Mode_Vouchers
Else
UploadedM = "Skipped"
Assistant_Mode_Vouchers
End If
End Sub
Sub Assistant_Mode_Vouchers()
If MsgBox("Do You Have a Vocuher Query file to be uploaded?", _
vbQuestion + vbYesNo, "Checking Vocuher Query File Existance") = vbYes Then
Z_Import_Voucher_2 'Calling another module code by its name
UploadedV = "Selected"
Final_step
Else
UploadedV = "Skipped"
Final_step
End If
End Sub
Sub Final_step()
MsgBox "You have selected below BSS Files!" & vbNewLine & vbNewLine & " 1. SIM Card Query File : " & UploadedR & vbNewLine & " 2. Package Query File : " & UploadedP & vbNewLine & " 3. Mobile Terminals Query File : " & UploadedM & vbNewLine & " 4. Vouchers Query File : " & UploadedV & vbNewLine & vbNewLine & "Now Go To Generation Step!", Title:="Assistant Mode Process Notification!"
End Sub
up to this point everything goes ok. but i added some validation process in which let the uploaded file to be validated if it is correct one or not.
This validation process exists in the external called sub For improting the file for Ex (Z_Import_Raw_SIMs_2).
and so on for every file of the 4 file types of the 4 questions.
So to discuss the issue and make it more clear
lets assume that we run the code and will go through the 4 questions
If we clicked yes that we have the file then import function is called here the rule of validations comes
IF the file was incorrectly choosen another message asks if you still have the file if we clicked yes and chose the right file this time
the 2nd questions comes if we clicked no and the same for the 2 remaining questions
the Expected result is to end processing after the final pop up message of Final_step () that telling us the selected files and the skipped ones
but the problem comes here then due to the first incorrectly chossen file.
as instead of end processing
it asks again for the non selected if we still need to import them or not
While trying to debug i found that
After perfoming the last command of Final_step () , it comes to the 3rd question to pass by end if then pass by its end sub and do the same for the 2nd question and the first one
then suddenly the debug curser moves to
EndIF
of the validation part
'First Validation for uploaded file using File Name
If InStr(OpenBookR2.Name, "Voucher") > 0 Or InStr(OpenBookR2.Name, "Mobile") Or InStr(OpenBookR2.Name, "Package") Then
SaveChanges = False
OpenBookR2.Close
MsgBox "You have not Chosen the right BSS File!" & vbNewLine & vbNewLine & "Please choose the right BSS RAW SIM File", Title:="Wrong Processing Notification!"
Assistant_Mode_Raw
End If
which is part of the import function like below
FileToOpenR2 = Application.GetOpenFilename(Title:="Browse for Raw SIMs File & Upload it", FileFilter:="Excel Files (*.xls*),*xls*")
If FileToOpenR2 <> False Then
Set OpenBookR2 = Application.Workbooks.Open(FileToOpenR2)
Set Rsheet2 = OpenBookR2.Worksheets("Default")
'First Validation for uploaded file using File Name
If InStr(OpenBookR2.Name, "Voucher") > 0 Or InStr(OpenBookR2.Name, "Mobile") Or InStr(OpenBookR2.Name, "Package") Then
SaveChanges = False
OpenBookR2.Close
MsgBox "You have not Chosen the right BSS File!" & vbNewLine & vbNewLine & "Please choose the right BSS RAW SIM File", Title:="Wrong Processing Notification!"
Assistant_Mode_Raw
End If
so any recommdantion to fix this looped IF