VBA reffrence to a table on a subform

kes

Registered User.
Local time
Today, 12:42
Joined
Mar 6, 2013
Messages
53
hi,
I have a form which have a sub form.
in the sub form I have a the direct table to update data on it.
example:
the form has the name of the project and the subform the name of one of the items of the same project and the table present the documents for the particular item.
the users have the option to add or edir docs to this item.

If I would like to reffer to a value they are entering on this table in VBA . how can I do that?
(I would like to present a msgbox when they are entering a date that isn't right on the table for this item.)

by the way, I can't use validation rule because I have a different dates needed per item.

hope I explained my self clearly.

thanks in advance!
 
If your subform's ControlSource is the direct link to the table, then there is no way to use VBA. You need a form in order to run VBA. I would recommend making a continuous form that looks like a table, but you can apply rules to it.
 
Data edits in forms go in one of two events depending on what you are trying to do. Simple edits that involve only the current control can go in the control's BeforeUpdate event. You would cancel the event if the edit failed.
Code:
If Me.txtSomeField < 99 Then
    Msgbox "SomeField must be >= 99.", vbOKOnly
    Cancel = True
    Exit Sub
End If
If the edit involves other fields or checks for nulls, it needs to go in the FORM's BeforeUpdate event.
Code:
If Me.txtSomeDate & "" = "" Then
    Msgbox "SomeDate is Required.",vbokOnly
    Cancel = True
    Me.txtSomeDate.SetFocus
    Exit Sub
End If
If Me.txtSomeDate < Me.txtSomeOtherDate Then
    Msgbox "SomeDate must be >= SomeOtherDate.", vbOKOnly
    Cancel = True
    Me.txtSomeDate.SetFocus
    Exit Sub
End If
 

Users who are viewing this thread

Back
Top Bottom