If text box is empty do nothing else do something

Dannyc989

Registered User.
Local time
Today, 01:52
Joined
Dec 18, 2013
Messages
46
Evening folks...

I am hoping someone can help with the below...

I have a form which has 2 text boxes on it one is for imputing a company name and one is for putting in a purchase order number. I want to be able to do the following but not sure of the coding:

If the company name text box is empty then do nothing but if it has a value then open a particular form

If the company name is empty but the purchase order number has a value I want it to open a different form.

If both are empty I want a message box which request something to be put in one of the text boxes.

Can anyone help

Regards

Daniel
 
Would this work?
Code:
 If Len(CompanyName) <> 0 then
      DoCmd.OpenForm {particular form}
 ElseIf Len(Nz(PurchaseOrder)) <> 0 then
      DoCmd.OpenForm {particular other form}
 Else
      MsgBox "Enter a value in one of the boxes"
 End if
 
I'm not to sure, I would like another opinion on this as I'm not sure if it would return an error... I'm not in the office at the moment so can't input it to try...
 
Code:
If Len(Trim(CompanyName & "")) <> 0 then
      DoCmd.OpenForm {particular form}
ElseIf Len(Trim(PurchaseOrder & "")) <> 0 then
      DoCmd.OpenForm {particular other form}
Else
      MsgBox "Enter a value in one of the boxes"
End if
 
Instad of
Code:
.. & ""

Try

Code:
.. & vbNullString

Its a good practice. In smaller routines such as yours, it won't make too much of a difference. But if you're using it in a larger routine, it will.

using "" creates a new isntance of a string. Where when calling vbNullString, you're calling a pre-declared and initialized variable.

pr2[Paul Eugin] Taught me this one a couple years back =]
 
Evening folks...

I am hoping someone can help with the below...

I have a form which has 2 text boxes on it one is for imputing a company name and one is for putting in a purchase order number. I want to be able to do the following but not sure of the coding:

If the company name text box is empty then do nothing but if it has a value then open a particular form

If the company name is empty but the purchase order number has a value I want it to open a different form.

If both are empty I want a message box which request something to be put in one of the text boxes.

Can anyone help

Regards

Daniel

I see what you're asking here, and I think that there may be a slight usability design flaw.

Create two separate buttons for loading these instances. Designing interfaces like this this confusing for a lot of users.

One step towards a better design would be to use this:
Code:
[ TEXTBOX ]    [ TEXTBOX ]
[  BUTTON ]    [  BUTTON ]

Two steps would be viable if you have each of these company names and purchase order nos in a database. You could use an auto-populated combo box.
Code:
[ COMBOBOX ]    [ COMBOBOX ]
[  BUTTON  ]    [  BUTTON  ]
 

Users who are viewing this thread

Back
Top Bottom