Opening Hyperlink dependant on field data (1 Viewer)

MooTube

Registered User.
Local time
Today, 07:42
Joined
Jul 2, 2015
Messages
31
I am attempting to open a website hyperlink, some of the fields contain https:// and some of them dont.

Code:
Private Sub Facebookbut_Click()

Dim Hyper As String
    
    If InStr([TEAMFacebook], "https") Then
        Hyper = Me.TEAMFacebook
    Else
        Hyper = ("https://www.facebook.com/" & Me.TEAMFacebook)
    End If
    
    Application.FollowHyperlink Hyper
    
 
End Sub

So far this does 2 things, it doesn't open any hyperlinks at all and continues to attempt to until the program is closed from task manager. Before I had this error it would open the hyperlink twice if the field does not contain "https" and the IF statement was passed to the 2nd option.

I have no idea why it is doing either of these things, but I might just be being dense!

Thanks in advance!
 
Last edited:

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 15:42
Joined
Jul 9, 2003
Messages
16,407
I don't think you need the brackets. Try:- Hyper = "https://www.facebook.com/" & Me.TEAMFacebook
 

MooTube

Registered User.
Local time
Today, 07:42
Joined
Jul 2, 2015
Messages
31
After changing it still gives me the same problem, access attempts to open the hyperlink until I close it from task manager :(
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 15:42
Joined
Jul 9, 2003
Messages
16,407
Code:
Private Sub Facebookbut_Click()

Dim Hyper As String
    
    If InStr([TEAMFacebook], "https") Then
        Hyper = Me.TEAMFacebook
    Else
        Hyper = ("https://www.facebook.com/" & Me.TEAMFacebook)
    End If
    
    Application.FollowHyperlink Hyper
    
 
End Sub

Try This:-

Code:
Option Compare Database
Option Explicit

Private Sub Command0_Click()

Dim Hyper As String
    
    If InStr([TEAMFacebook], "https") Then
        Hyper = Me.TEAMFacebook
        MsgBox " >>> With HTTP " & Hyper
    Else
        Hyper = "https://www.facebook.com/" & Me.TEAMFacebook
        MsgBox " >>> NO HTTP " & Hyper
    End If
    
    Application.FollowHyperlink Hyper

End Sub
 

MooTube

Registered User.
Local time
Today, 07:42
Joined
Jul 2, 2015
Messages
31
The good news is that this stops the program from crashing! it still opens 2 tabs if the URL does not contain https://

And Ideas?
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 15:42
Joined
Jul 9, 2003
Messages
16,407
Show the contents of the message boxes
 

MooTube

Registered User.
Local time
Today, 07:42
Joined
Jul 2, 2015
Messages
31
when http is present: ">>> WITH HTTP (full address line)"

when http is not present " >>> NO HTTP (full address line)"

It doesnt show the same address twice, and the code is the same for when http is present or not present, but for some reason it opens twice when http is not present :S
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 15:42
Joined
Jul 9, 2003
Messages
16,407
I need to see the contents.

You can copy the contents of the message box using Ctrl C. Paste here, paste everything! All of the text that gets copied as I can see better what is happening.
 

MooTube

Registered User.
Local time
Today, 07:42
Joined
Jul 2, 2015
Messages
31
---------------------------
Microsoft Access
---------------------------
>>> With HTTP https://www.facebook.com/labotijatapas?rf=112247058835384
---------------------------
OK
---------------------------




---------------------------
Microsoft Access
---------------------------
>>> NO HTTP https://www.facebook.com/barsportcannock
---------------------------
OK
---------------------------


now that I have posted these it has gone back to not opening anything and freezing up, I didn't change anything in the code from this morning, and now it has stopped working!
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 15:42
Joined
Jul 9, 2003
Messages
16,407
Create a new form from scratch, no copying, a very simple form, just an unbound text box named "TEAMFacebook" and a command button.

Place the code:-

Code:
Private Sub Command0_Click()

Dim Hyper As String
    
    If InStr([TEAMFacebook], "https") Then
        Hyper = Me.TEAMFacebook
        MsgBox " >>> With HTTP " & Hyper
    Else
        Hyper = "https://www.facebook.com/" & Me.TEAMFacebook
        MsgBox " >>> NO HTTP " & Hyper
    End If
    
    Application.FollowHyperlink Hyper

End Sub

Place the code in the command button, set the default value of he textbox to tony.hine, test, change the text box contents, check, and report back.
 

MooTube

Registered User.
Local time
Today, 07:42
Joined
Jul 2, 2015
Messages
31
I have made a blank form with only a text box and a button, the buttons onclick event is the code you posted.

when the button is clicked the message box opens as usual, however access then decides to freeze up and I have the same problem. This also happens if I change it to a with https address.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 15:42
Joined
Jul 9, 2003
Messages
16,407
You might need to change the code to something like:-


Code:
Private Sub Command0_Click()

Dim Hyper As String
    
    If InStr([TEAMFacebook], "https") Then
        Hyper = "http://www.microsoft.com"
        MsgBox " >>> With HTTP " & Hyper
    Else
        Hyper = "http://www.microsoft.com"
        MsgBox " >>> NO HTTP " & Hyper
    End If
    
    Application.FollowHyperlink Hyper

End Sub
 

MooTube

Registered User.
Local time
Today, 07:42
Joined
Jul 2, 2015
Messages
31
Same again, I changed "tony.hine" to a real microsoft address "/gb-en/" so that it would find the address. It still freezes when clicking the button. it seems like it is constantly attempting to finish the request but it is never able to
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 15:42
Joined
Jul 9, 2003
Messages
16,407
Well the only other thing to try is to create a completely new database and do the same in there and see what happens.
 

Uncle Gizmo

Nifty Access Guy
Staff member
Local time
Today, 15:42
Joined
Jul 9, 2003
Messages
16,407
Again build everything from scratch, do not do any copying and pasting, don't use any tables or anything, just a very simple basic database.
 

MooTube

Registered User.
Local time
Today, 07:42
Joined
Jul 2, 2015
Messages
31
Im gonna keep working at it, if I come into anything I will let you know!
 

Users who are viewing this thread

Top Bottom