Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If textbox is null, display msgbox

Status
Not open for further replies.

JamesCurtis

Programmer
Aug 22, 2006
9
US
Hey guys, I'm running into some major problems here. I'm running a run-time environment for a computer service database. My people like to use Cash Customer (one account for multiple people, bad idea i know) to enter the costumers' computer problems into the service DB. on my form I have a print button, which checks to see if it's a new service (via a textbox) then if it's new it'll e-mail me and another person.

I want to add another step into the equation. I'm going to try to force them to put the user information into the Notes field if they decide to use cash customer, and not try to enter first/last name into the cash customer's record, because it gets changed after each time a new cash customer is entered, which results in confusion when we look back in the records and we don't have the names of the customers anymore. What I'm trying to do is have it detect if the customer ID is cash customer, then if it is, open the notes form if the notes field is blank and tell them that they need to enter the user information there. If the notes section isn't blank, it'll close the form and continue to print the service ticket out that we attach to computers. Here's the code

"
Dim stDocName As String
Dim stDocName2 As String
Dim stDocName3 As String
Dim stLinkCriteria As String

stDocName = "Print"
stDocName2 = "Service Record"
stDocName3 = "Notes"



If [newcheck] = True And [CustomerID] = "CASH COUNTER CUSTOMER" Then
DoEvents
stLinkCriteria = "[Service Number]=" & Me![Service Number]
DoCmd.OpenForm stDocName3, , , stLinkCriteria
If [Notes] = Null Then
MsgBox "Please enter the name of the cash customer in the notes, thank you :)"
Else
DoCmd.Close acForm, "Notes", acSaveYes
End If
End If


If [newcheck] = True Then
DoEvents
stLinkCriteria = "[Service Number]=" & Me![Service Number]
DoCmd.OpenForm stDocName2, , , stLinkCriteria
DoCmd.RunMacro stDocName
DoCmd.RunCommand acCmdPrint


ElseIf [newcheck] = False Then
MsgBox "This is not a new customer, will not e-mail"

stLinkCriteria = "[Service Number]=" & Me![Service Number]
DoCmd.OpenForm stDocName2, , , stLinkCriteria
End If
"

Pardon me for my crappy programming skills, i've only had one semester of VB two years ago and i Haven't messed with it since :)

Thanks!
 

I believe they are parts of codes missing in this and I am not sure what you had not working, but i believe it is this part

Code:
        If [Notes] = Null Then
        MsgBox "Please enter the name of the cash customer in the notes, thank you :)"
        Else
        DoCmd.Close acForm, "Notes", acSaveYes
        End If

I believe you cant test if a certain control is null, you actually need to put it like this

Code:
        If [red]Not Null(Notes)[/red] Then
        MsgBox "Please enter the name of the cash customer in the notes, thank you :)"
        Else
        DoCmd.Close acForm, "Notes", acSaveYes
        End If

I am not sure about this
Code:
 If [newcheck] = True And [red][CustomerID] = "CASH     COUNTER CUSTOMER"[/red] Then


Hope this helps...

"Knowing that you know is the greatest sign of stupidity, knowing that you are ignorant is the best proof of intelligence.
 
If the users are in the habit of doing things a certain way, it is often difficult to get them to change. Have you considered simply writing the "first/last name" That they put "into the cash customer's record" to the notes field, with or without a message to say "this has been done, please confirm"?

As regards the notes form, if you decide to take this path it will be necessary to check the field in a different event. Have a look at:
KISS way to force users to click a command button to exit a form regardless of menu or toolbar options
faq702-2071

It is always best to check for both null and a zero length string, which this will do:
[tt]If If Trim([Notes] & " ") = "" Then[/tt]

Why all the Do Events? [ponder]
 
This is incomplete code, I just put in the meat of the code where it seems to be screwing up. It gets all the way into the If [Notes] = Null and then gives me the "Object doesn't support this property or method" error. I tried changing it to something along the lines of
"If IsNull(Notes) Then"
msgbox etc.etc. blah blah

but if I did that it just skipped that whole deal and went on to e-mailing me and my partner and trying to print it.

BTW, all it's missing is the private sub click and error statements.
 
Then it is as Remou said, if it is null, yet seems empty, it is set to 0, and the trim function he provided will do what you want.

Maybe providing the whole code would help us understand =/ I think Remou also had a big ? on his face reading this.

Hope this helps

"Knowing that you know is the greatest sign of stupidity, knowing that you are ignorant is the best proof of intelligence.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top