How to: Disable CommandButton if Query results are not null.

  • Thread starter Thread starter AndrewB
  • Start date Start date
A

AndrewB

Could someone give me VB code please?

I need to set the "Enabled" property of CommandButton1 to "No" if "Field1"
in Query1 is not null.

This is for error handling of form. I need to disable a command button,
that runs a macro, if data exists in "Field1" of Table1. I am clueless when
it comes to VB unfortunately.

Thanks,
 
AndrewB said:
Could someone give me VB code please?

I need to set the "Enabled" property of CommandButton1 to "No" if "Field1"
in Query1 is not null.

This is for error handling of form. I need to disable a command button,
that runs a macro, if data exists in "Field1" of Table1. I am clueless
when
it comes to VB unfortunately.


You probably need to check for the condition in both the form's Current
event (to enable/disable for each record as you come to it) and in the
AfterUpdate event of Field1 (for when the user enters or deletes data from
that field). In the Current event, you also need to handle the possibility
that the command button has the focus. So you might have these event
procedures:

'----- start of example code -----
Private Sub Form_Current()

If IsNull(Me!Field1) Then
Me!CommandButton1.Enabled = True
Else
If Me.ActiveControl.Name = "CommandButton1" Then
Me!Field1.SetFocus
End If
Me!CommandButton1.Enabled = False
End If

End Sub

Private Sub Field1_AfterUpdate()

Me!CommandButton1.Enabled = Not IsNull(Me!Field1)

End Sub
'----- end of example code -----

I hope I haven't got the logic backwards.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top