Danives
asked on
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
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
ASKER
Sorry forgot 2 mention it, Im using M$ Access, hoping to use the validation rule to fix my problem. Thanx
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
ASKER
Thanks for all your help guys, its working!!!
M$ Access you could have a validation rule and for Sql server or any others
you could have a trigger on update or insert.