Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 297
  • Last Modified:

How to ensure default value is kept?

Hi,

I have a table which includes links e.g. www.google.com, however I wish to make sure that these links always have the value of http:// at the front and if they dont, to come up with an error message telling the user to enter http:// at the front of the link. I know this can be done using validation rules but I am not entirely sure what coding to use as all I have tried has failed. Thanks in advance,

Dan
0
Danives
Asked:
Danives
  • 3
  • 2
  • 2
  • +1
2 Solutions
 
danthsCommented:
not sure which db you are using?

M$ Access you could have a validation rule and for Sql server or any others
you could have a trigger on update or insert.
0
 
DanivesAuthor Commented:
Sorry forgot 2 mention it, Im using M$ Access, hoping to use the validation rule to fix my problem. Thanx
0
 
danthsCommented:
oops clicked submit too fast..
pseudo code:-

if (lcase$(left(myColumn, 7)) = "http://") then
   proceed...
else
   Raise Error "Not a valid url"
end if

and where RE 's are supported
^http\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(/\S*)?$
0
NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

 
DanivesAuthor Commented:
Im sorry I am not very proficent in using coding in MS Access, does this go into the validation field or do I have to enter this into visual basic through Access?
0
 
rockiroadsCommented:
on the beforeupdate event of the textbox (assuming thats what they use to enter the hyperlink) or whatever else control


private sub xxx_BeforeUpdate(Cancel as Integer)

    if left$(xxxx.Value, 7) <> "http://" then
       msgbox "URL must begin with http://"
       Cancel = True
     end if
end sub


basically check first 7 characters of the control called xxxx, if it does not equal http:// then throw error, set cancel to true so that user remains on that field

   
0
 
YounkmanCommented:
Danths code is VB, if you want to use the table wizard and vaildation rules, heres how you would write it: (this is simply a mod of his code)

Validation Rule: LCase$(Left([mycolumn],7))="http://"
Validation Text: Please use http:// at the beginning of the URL

Where mycolumn is the name of the column you want the validation rule to apply to.

Cheers,
Younkman
0
 
rockiroadsCommented:
sorry, forgot to add
danths has used the left command, that is the best method to use when checking for starting characters

danths has also converted the user entered value into lowercase, which helps

you could of course not throw an error and automatically place a http:// in front


private sub xxx_BeforeUpdate(Cancel as Integer)
    if left$(xxxx.Value, 7) <> "http://" then xxxx.value = "http://" & xxxx.Value
end sub

also, does this just use http://, can you enter ftp://, file:// etc

0
 
DanivesAuthor Commented:
Thanks for all your help guys, its working!!!
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now