Insert Text Into Form Field In Needed

ToddNYC

Registered User.
Local time
Today, 07:10
Joined
Sep 24, 2012
Messages
23
Hello, I have a field called "url" in my form. When saved to table, it needs to contain "h t t p : / /" (without the spaces!) before the user types the standard URL address, but field needs to be empty if no URL is entered. I can't figure out how to do this.

I've tried adding it as default text of "h t t p : / /" (also without the spaces!) but this fills in data all the time, and I've tried creating a checkbox to enable the text field (using VBA code below) but it doesn't seem to work either. Also tried using OnChange, but no luck there either. Is there a way to do this? Thank you!
Private Sub Check60_AfterUpdate()

If Me.Check60 = True Then
Me.url.Enabled = True
Else
Me.url.Enabled = False
End If

End Sub

 
Welcome to the forum

The following code in your Form's Before Update event should do the trick;
Code:
    If Me.url = "http://" Then
        Me.url= ""
    End If
 
Hi John, thanks for the welcome and thank you for the quick response to my question.

I didn't get that exact code to work for me, but you did send me off in the direction to find the solution, so thank you.

Here's what I did:

Code:
Private Sub url_AfterUpdate()
    newString = Left(url, 7)
    If newString <> "h ttp: //" Then
        Me.url = "h ttp: //" & Me.url
    End If

End Sub
 
Last edited:

Users who are viewing this thread

Back
Top Bottom