i am using the same form for Editing and Addition of new record (say Purchase Entry).
I dont want to allow user to edit PO_No (Purchase Order No) if the same is used in Sales Table (tblSale)
On Load event of the form, i am using below code :
Private Sub Form_Load()
'If Me.AllowEdits = True Then
'If Me.DataEntry = False Then
If Me.NewRecord = False Then ' to check if its in Edit Mode
Dim poid As String
Dim stlinkCriteria As String
MsgBox "Form is in edit mode"
poid = Me.PO_No.Value
stlinkCriteria = "[PO_NO]=" & "'" & poid & "'"
If DCount("PO_NO", "tblsale", stlinkCriteria) > 0 Then
MsgBox "Dcount of total sales records :" & DCount("PO_NO", "tblsale", stlinkCriteria)
Me.txtPO_no.Enabled = False
MsgBox "This PO No can not be edited as this is used in sale Master", vbOKOnly, "ERROR"
Me.txtPO_no.Enabled = True
MsgBox stlinkCriteria, vbOKOnly
Till now its working fine, but when the form is used for new record, textbox PO_NO is automatically disabled. :(
Could you please help ?
Thanks in advance.