lundi 22 mars 2021

Multiple VbQuestions Connected to Multiple GetOpenFilename and a validation for the imported files

I need to use vbquestion 4 times as below

  1. First 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

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 till 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 and this validation exists in the external called sub For Ex(Assistant_Mode_Mobile) and so on for everyone of them. so to discuss the issue and make it more clear

lets assume that in using the first sub Assistant_Mode_Raw for example and the user clicked yes then import function is called which is located in another code module. but if the wrong choosen file is selected by user, validation occurs then and everything goes ok too untill we reach the last part of the message of the final selected files after the final message appears (This message related to the last sub "Sub Final_step()")

after clicking okay the wrong selected files Vbaquestion only appears again to ask if you need to upload them or not many times untill this message goes away.

So, when i debuged the code i found that debug indicates that the problem in ending the if statements which exists in the validation code. which must end it then comes back again to the original sub

maybe this issue is due to a bad code structure or due to lack of knowledge of my side so i'm appreciating your support for this the best solution of this issue

Part of uploaded file code and its validation

 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

Part of the other code module:

    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
      

lastly this issue occurs only when the selected file is the incorrect one.

Aucun commentaire:

Enregistrer un commentaire