Solved

How to ensure default value is kept?

Posted on 2004-05-03
8
280 Views
Last Modified: 2012-08-13
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
Comment
Question by:Danives
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 6

Expert Comment

by:danths
ID: 10976520
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
 

Author Comment

by:Danives
ID: 10976557
Sorry forgot 2 mention it, Im using M$ Access, hoping to use the validation rule to fix my problem. Thanx
0
 
LVL 6

Assisted Solution

by:danths
danths earned 250 total points
ID: 10976578
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
 

Author Comment

by:Danives
ID: 10976640
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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 65

Expert Comment

by:rockiroads
ID: 10977290
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
 
LVL 3

Accepted Solution

by:
Younkman earned 250 total points
ID: 10977315
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
 
LVL 65

Expert Comment

by:rockiroads
ID: 10977316
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
 

Author Comment

by:Danives
ID: 10977440
Thanks for all your help guys, its working!!!
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Database tuning – How to start and what to tune. This question is frequently asked by many people, both online and offline. There is no hard and fast rule-of-thumb for performance tuning, however, before beginning the tuning process one should a…
APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now