[AccessD] Form Validation
wrwehler at gmail.com
Sat Oct 29 20:00:17 CDT 2022
Got it to work!
Private Sub Command2_Click()
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset("Table1")
Dim f As String, z As String
f = Chr(34) & Me(rst!Field1) & Chr(34) 'field to eval
z = Replace(rst!Field2, "<fldval>", f) 'function to modify
Set rst = Nothing
On Sat, Oct 29, 2022 at 7:54 PM Ryan W <wrwehler at gmail.com> wrote:
> Having a bit of a snafu on this. When I do this the strEval turns into
> so I get an error "cannot find the name theActualFieldValue you entered in
> the expression" message... I assume because it's thinking
> theActualFieldValue should be some sort of object to evaluate since it's
> not wrapped in quotes?
> > 'Create Eval string
> >strFldVal = Me(strFld)
> >strEval = Replace(rst.FunctionToEval, "<fldval>", rst.FieldToScrutinize)
> >If Eval(strEval) ....
> On Sat, Oct 29, 2022 at 6:07 PM Stuart McLachlan <stuart at lexacorp.com.pg>
>> First impression:
>> Colours are 4byte integers (LONGs) (with the top byte unused for RGB
>> (And Project and Client keys as varchars() is a bit on the nose too :) )
>> That said - Eval doesn't recognise "me".
>> You'll need to do something like:
>> 'Record in table:
>> FieldToScrutinize "ExtraFld1"
>> FunctiomToEval = "Len(<fldval>) > 0"
>> Then in your function
>> 'Create Eval string
>> strFldVal = Me(strFld)
>> strEval = Replace(rst.FunctionToEval, "<fldval>", rst.FieldToScrutinize)
>> If Eval(strEval) ....
>> On 29 Oct 2022 at 16:48, Ryan W wrote:
>> > I thought I had emailed about this before but I cannot find it. Maybe
>> > it got lost somewhere along the way or I thought about emailing and
>> > never did.
>> > I've got a form we use to log in client data, there are some extra
>> > fields that are NOT required by every client so I can't put backend
>> > constraints on them.
>> > I was wondering if I could write a table such as:
>> > ClientID varchar(100)
>> > Project varchar(100)
>> > FieldToScrutinize varchar(100)
>> > FunctionToEval varchar(255)
>> > ForeColor varchar(50)
>> > BackColor varchar(50)
>> > So lets say we have ClientA, Project B, FieldToScrutinize is
>> > "ExtraFld1"
>> > FunctionToEval would be something like Len(me!extrafld1) = 0
>> > So then in the form code we have something like
>> > rst = currentdb.openrecordset("SELECT * FROM ValidationRules WHERE
>> > ClientID = '" & me.ClientID & "'")
>> > do until rst.eof
>> > if Eval(rst!FunctionToEval) = false then
>> > me(FieldToScrutinize).BackColor = rst!BackColor
>> > me(FieldToSTrutinize).ForeColor = rst!ForeColor
>> > end if
>> > rst.MoveNext
>> > loop
>> > I guess my question is, will EVAL work in that manner? That way all
>> > my validation rules for these specific clients can be managed in a
>> > table rather than adding code and having to distribute a new FE when
>> > rules are modified? -- AccessD mailing list
>> > AccessD at databaseadvisors.com
>> > https://databaseadvisors.com/mailman/listinfo/accessd Website:
>> > http://www.databaseadvisors.com
>> AccessD mailing list
>> AccessD at databaseadvisors.com
>> Website: http://www.databaseadvisors.com
More information about the AccessD