Close a form if Combobox Text = ""

Sam Summers

Registered User.
Local time
Today, 07:08
Joined
Sep 17, 2001
Messages
939
Hi guys,

I'm not awake this morning and I am trying to do as the title says but seeing as I haven't been using Access for a while I just cant get my head round even this simple thing!!!!

This is the code I am using but at the moment I am getting the error - Else without an If?

Private Sub Form_Open(Cancel As Integer)

InsideHeight = 5000
InsideWidth = 7695

If Me.ClientName.Text = "" Then DoCmd.Close
Else

End If

End Sub


I have tried various solutions but I just chased the problem around?

Thank you in advance for helping my stupidity
 
Try move the DoCmd.Close to the next line or delete Else and End If.
 
Hi there and thanks for answering.

Tried that and still getting an error?

Also tried this and variations of it:


If IsNull(ClientName) Then DoCmd.Close
Else
DoCmd.OpenForm "SelectClient", acNormal
InsideHeight = 5000
InsideWidth = 7695

'End

End If



Still not compiling? :confused:
 
Like JHB said :
move the DoCmd.Close to a new line...
If Isnull(ClientName) Then
DoCmd.Close
Else
....
End If
 
on the form's open event, the controls haven't been initialized yet. meaning it does not exists yet and has no value.

do it in the other form's event, ie, load, activated.
 
Thank you guys SO much for your help.

I took all your advice and this was what I have now in the correct Event:


Private Sub Form_Load()

If IsNull(ClientName) Then
DoCmd.Close
Else
DoCmd.OpenForm "SelectClient", acNormal
InsideHeight = 5000
InsideWidth = 7695

End If

End Sub
 
is it now working?
 
It is with a small tweek as below. Thank you very much


Private Sub Form_Load()

If IsNull(ClientName) Then
DoCmd.OpenForm "Main", acNormal
DoCmd.Close acForm, "SelectClient", acSaveNo
Else
DoCmd.OpenForm "SelectClient", acNormal
InsideHeight = 5000
InsideWidth = 7695

End If

End Sub
 
...on the form's open event, the controls haven't been initialized yet. meaning it does not exists yet and has no value...
It not only doesn't have a Value, but it can't receive Focus, which is needed in order to reference .Text, on any Control. Far better, in Access VBA, to use .Value, which doesn't require Focus!

Linq ;0)>
 
Hi linq, The code in my final post works fine but I understand what you are explaining. Thank you for your additional advice. :)
 

Users who are viewing this thread

Back
Top Bottom