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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code Skipping Section

Status
Not open for further replies.

xeb

Technical User
Nov 14, 2003
81
US
Why is the following code skipping this section...

If strPasswd = "" Or strPasswd = Empty Then
MsgBox "No password entered.", vbInformation, "Password Required"
Exit Sub
End If

When I run it if you leave txtPassword blank you receive the "Sorry, you do not have access to the Student Report."
message, which is suppose to be for an incorrect password.


------------------------------------------------------------


Private Sub Command2_Click()

Dim strPasswd

strPasswd = Me.txtPassword

'Check to see if there is any entry made to input box, or if
'cancel button is pressed. If no entry made then exit sub.

If strPasswd = "" Or strPasswd = Empty Then
MsgBox "No password entered.", vbInformation, "Password Required"
Exit Sub
End If

'If correct password is entered open TPA form
'If incorrect password entered give message and exit sub

If strPasswd = "5BrownSt." Then
DoCmd.OpenForm "RunStudentReportForm", acNormal '*Change this line

Else
MsgBox "Sorry, you do not have access to the Student Report.", vbOKOnly, "Restricted Report"
Exit Sub
End If

End Sub
 
strPassword is most likely null. Try:


If Trim(strPasswd & "") = "" Then
 
or:
Code:
[blue]   If Nz(strPasswd,"") = "" Then[/blue]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
The problem with Nz is that is does not trap the unlikely but not impossible case of a space filled string.
 
Remou said:
[blue]The problem with Nz is that is does not trap the unlikely but not impossible case of a space filled string.[/blue]
For a string variable in VBA sure ... but not a textbox (as the op is checking). [blue]Access doesn't allow space only in textboxes![/blue] . . .


Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
It is possible to get a space-filled field in Access in certain odd circumstances via imports - it used to be a bit of a problem in earlier versions, and older Access examples include:

If len(trim(string))=0 then

It can also be a problem when attaching to other back-end databases.

Dim strPasswd: Certainly a textbox value is written to it, but it starts out life as a variant. Yesno?

 
You've taken a jump from [blue]simple data entry[/blue] to [purple]certain odd circumstances via imports![/purple] [surprise]

The op is not importing data [surprise]

Calvin.gif
See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
xeb - I strongly urge you to declare your variables as specific types (set your VBA to Option Explicit to force you to do it). Leaving it as a variant leads to all sorts of ambigiouty in your code.

Had you done this:
Code:
Dim strPassword As String

It never would have become Null, and additionally you would not have to check for Empty.

Joe Schwarz
Custom Software Developer
 
I think you may have missed a line:

"It can also be a problem when attaching to other back-end databases.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top