Solved Visible and invisible Button in the form. (1 Viewer)

urjudo

Member
Local time
Today, 16:03
Joined
Oct 9, 2020
Messages
67
Hi,
I have a button named View Orders in a form, the cmdViewOrders will open the SharePoint folder which is associate with the case#. The Path is C:\Users\" & Environ("UserName") & "\SharePoint\CasesDoc\" & Folder\& "\" & SPCaseName
for example: C"\Users\Mary.Smith\SharePoint\CasesDoc\A-F\Doe, John vs. Jones, Jenny_C12345678 -- > this is the path will be open when user(s) on the case C12345678 and click the View Orders in this case

I would like to do is if there is no such case (Doe, John vs. Jones, Jenny_C12345678 in the A-F folder (the Folder is base on the Plaintiff's first letter of the last name).

Code:
Below is my code in the Form_Current()
Dim MyPath As String
Dim NameLetter As String
Dim Folder As String
Dim PLLetter As String
Dim CaseName As String

Dim db As Database
Dim rs As RecordSet
Dim db = CurrentDb

Set rs = db.OpenRecordSet("Select CLName, PLName from qrySharPointNameList Where CLCASENUM = " & Chr(34) & Me.CLCASENUM & Chr(34), dbOpenDynaset, dbSeeChanges)
     CaseName = rs!PLName & " vs. " & rs!CLName
rs.Close

PLLetter = Left([CaseName],1)
NameLetter = PLLetter
SPCaseName = CaseName & "_" & Me.CLCASENUM

Select Case True
    Case NameLetter >="A" And NameLetter <="F"
            Folder = "A-F"   
    Case NameLetter >="G" And NameLetter <="L"
            Folder = "G-L"
    Case NameLetter >="M" And NameLetter <="R"
            Folder = "M-R"
   Case NameLetter >="S" And NameLetter <="X"
            Folder = "S-X"
   Case NameLetter >="Y" And NameLetter <="Z"
            Folder = "Y-Z"
    End Select

I tried:
MyPath = "C:\Users\" & Environ("UserName") & "\SharePoint\CaseDoc\" & Folder & "\" & SPCaseName

If Dir(MyPath) <> " " then
   cmdViewOrders.visible = True
Else
   cmdViewOrders.visible = false
End if

I also tried:
    MyPath = Dir("C:\Users\" & Environ("UserName") & "\SharePoint\CaseDoc\" & Folder & "\" & SPCaseName)

   If (MyPath) <> " " then
      cmdViewOrders.visible = True
   Else
      cmdViewOrders.visible = false
  End if

My problem here is the cmdViewOrders shows on every case, it seems not checking on the Path. Both are either cmdViewOrders visible or the cmdViewOrders invisible on all cases no matter if the case is exist in the folder or not.

Any help will be great appreciate!

Thank you
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 14:03
Joined
Aug 30, 2003
Messages
35,406
Two thoughts. First, you need an Else clause to set it False. Second, you're testing for a space rather than an empty string. Delete the space inside the quotes.
 

urjudo

Member
Local time
Today, 16:03
Joined
Oct 9, 2020
Messages
67
@Paul,
I just added the Case Else also moved the space inside quote but the result still the same as I mention before
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 14:03
Joined
Aug 30, 2003
Messages
35,406
There is still a space here:

If Dir(MyPath) <> " " then

should be

If Dir(MyPath) <> "" then
 

urjudo

Member
Local time
Today, 16:03
Joined
Oct 9, 2020
Messages
67
@Paul,
Sorry, I did not post the one that I changed. Yes, I did like your but it's still the same result
 

urjudo

Member
Local time
Today, 16:03
Joined
Oct 9, 2020
Messages
67
Code:
Select Case True
    Case NameLetter >="A" And NameLetter <="F"
            Folder = "A-F"  
    Case NameLetter >="G" And NameLetter <="L"
            Folder = "G-L"
    Case NameLetter >="M" And NameLetter <="R"
            Folder = "M-R"
   Case NameLetter >="S" And NameLetter <="X"
            Folder = "S-X"
   Case NameLetter >="Y" And NameLetter <="Z"
            Folder = "Y-Z"
  Case Else
           msgbox("No Folder found.")
   End Select


  MyPath = Dir("C:\Users\" & Environ("UserName") & "\SharePoint\CaseDoc\" & Folder & "\" & SPCaseName)

   If (MyPath) <> "" then
      cmdViewOrders.visible = True
   Else
      cmdViewOrders.visible = false
  End if
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 14:03
Joined
Aug 30, 2003
Messages
35,406
Actually try

Debug.Print "C:\Users\" & Environ("UserName") & "\SharePoint\CaseDoc\" & Folder & "\" & SPCaseName
 

Minty

AWF VIP
Local time
Today, 22:03
Joined
Jul 26, 2013
Messages
8,831
If the file/folder may not exist I think you need

Dir(YourPath, vbDirectory)

?
 

urjudo

Member
Local time
Today, 16:03
Joined
Oct 9, 2020
Messages
67
@Paul, I did debug it, but it shows no an error except it doesn't know how to check on the "IF" statement.

@Minty, that it is! after I added the vbDirectory inside the Dir(MyPath), it works like it suppose to.

Thank you both for your time.

Do I just click solved or is there point for both of you? I'm not sure how it works when close the question because this is my second thread since I registered to this site.

I will open another thread regarding the the above code in the cmdViewOrders, it opens the correct Case Folder which associate with the case but after I added the first name then it open the users documents folder (This PC\Documents). I can's figure it out.

Thanks again!
 

urjudo

Member
Local time
Today, 16:03
Joined
Oct 9, 2020
Messages
67
@Minty,
Can you explain to me why I need to add the vbDirectory if you don't mind? Thank you
 

Users who are viewing this thread

Top Bottom