Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check against ValidationRule in VBA

Status
Not open for further replies.

Frink

Programmer
Mar 16, 2001
798
GB
Hallo,

I was about to post this question when I found the BuildCriteria function which does everything I need!


Does anyone know how to perform the same check as a table field validation rule in VBA?

i.e I want to write a function which takes a value and a ValidationRule string and returns True or False. The thing is I want it to work with any ValidationRule, ie:
'-1 or Between 1 and 100'

Obviously there must be code within Access to do this, as you can add a ValidationRule string into the criteria box of a query in design view then it turns it into a valid SQL expression, i.e.
In a new query design, add any table, then add a field with the following set:
Expr1: 0
Show: Yes
Criteria: -1 or Between 1 and 100'
Set the query Top Values property to 1

If you look at the SQL View you get:
SELECT TOP 1 0 AS Expr1
FROM tblTable
WHERE (((0)=-1 Or (0) Between 1 And 100));

If you run this, then you only get a record returned if the value (in this case 0) is allowed by the expression.

I've looked at Eval, but this won't expand the expression so is no use.

Is it possible to programatically create a query?
 
Yes - it is possible to create a query.

Look at "CreateQueryDef" in the Access help file.

John
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top