Check if Table field is empty (1 Viewer)

pds8475

Registered User.
Local time
Today, 10:22
Joined
Apr 26, 2015
Messages
84
Hi
I'm trying to write code on the OnLoad event of my form(FrmOfficeCust) which checks to see if a field on the Table(CustomerTable) is Empty using the field Customer to find the record. If not disable a textbox(ConTxt) on the form.

Form = FrmOfficeCust
Table= CustomerTable
Field to find record = Customer
TextBox for Customer =CustTxt
Field being checked = Contact
TextBox for Contact= ConTxt

I expect the code will look something like this

Code:
 Private Sub Form_Load()
 
CustTxt.Value = Forms!FrmOfficeSearch.OfficeSubform!Customer

 If IsNull(CustomerTable.Contact) WHERE Customer ='" & [CustTxt] & "' Then
       ConTxt.Enabled =True
Else
     ConTxt.Enabled = False
 
End If
 End Sub
But obviously my IF statement s wrong

Any Help would be greatly appreciated
 
Last edited:

JHB

Have been here a while
Local time
Today, 11:22
Joined
Jun 17, 2012
Messages
7,732
What is the recordsource for the form?
 

pds8475

Registered User.
Local time
Today, 10:22
Joined
Apr 26, 2015
Messages
84
At this moment a record source hasn't been set. But if I need to do this then it would be the customer table. The CustTxt textbox however is just being passed a value from another form.
I am using the following code to update the Table(CustomerTable) on a Onclick event of a button.

Code:
 Private Sub Command1_Click()
DoCmd.SetWarnings False
DoCmd.RunSQL "Update CustomerTable SET Contact = '" & Me!ConTxt & "'  WHERE Customer ='" & [CustTxt] & "'"
DoCmd.SetWarnings True
End Sub
 

pds8475

Registered User.
Local time
Today, 10:22
Joined
Apr 26, 2015
Messages
84
Okay I take it your point is that I needed to fetch the data from the table?

So I have put the Code

Code:
 Private Sub Form_Load()
    CustTxt.Value = Forms!FrmOfficeSearch.OfficeSubform!Customer
    ConTxt = DLookup("ConTxt", "CustomerTable", "Customer ='" & [CustTxt] & "'")

 If IsNull(Me.ConTxt) Then
        ConTxt.Enabled = True
    Else
        ConTxt.Enabled = False
   End If
 End Sub

Which Works
So thanks For the pointer :)
 

JHB

Have been here a while
Local time
Today, 11:22
Joined
Jun 17, 2012
Messages
7,732
Good you got it solved (on your own)! :D
 

Users who are viewing this thread

Top Bottom