If statement involving child table

lydz

Registered User.
Local time
Today, 05:35
Joined
Mar 6, 2006
Messages
28
so ive got a form that has a sub form (think thats it) and its linked to another table
im trying to do an If statement (in vb) and i want to involve a field in the table that subform is on, but dont know how
basically what the thing is is

if the field in that child table = 2 Then
MsgBox("Do not allow")
ENd IF

just dont know how to point to that field

any help would be great thanks
 
lydz,

I'm assuming that the Child table has many records for each Parent record.

There is no guarantee that the subform is pointing to the correct record.

I'd use the DCount function:

Code:
If DCount("[ThatField]", _                            ' <-- The field that shouldn't = 2
          "ChildTable", _                             ' <-- Your Child table
          "[ChildID] = " & Me.ChildID & " And " & _   ' <-- Assume a numeric key
          "[ThatField] = 2") > 0 Then                 ' <-- That field can't = 2
   MsgBox("Do Not Allow")
End If

Wayne
 

Users who are viewing this thread

Back
Top Bottom