Invalid user of Null: Runtime error 94. Getting error when textbox is Blank. How to handle this error:

pedie

Well-known Member
Joined
Apr 28, 2010
Messages
3,875
Original code. username below is textbox name.
Please help.
Code:
[/FONT]
[FONT=Courier New]Private Sub Command9_Click()
If Me.Username.Value = "" Then MsgBox "Username cannot be blank", vbInformation, "OK?": Exit Sub
MsgBox Me.Username.Value
End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Try
Code:
    if len(Me.Username.value & "") = 0 then
        msgbox "Username may not be blank.", vbinformational
        Me.Username.Setfocus
        exit sub
    end if

Jack
 
Upvote 0
Pedie,
Perhaps an alternative. If your form is bound to a table and you want to ensure that the field username is not null, then in your table properties for the filed, set it to required.

Alan
 
Upvote 0
Code:
    If Len(Nz(Me.Username.Value)) = 0 Then
        MsgBox "Username may not be blank.", vbInformation
        Me.Username.SetFocus
        Exit Sub
    End If
 
Upvote 0
Thanks Alan, Dogsday and thanks James:)

Thanks alot and may I also ask, what is nz in that code line?

And one more thing how do i make the code select the table called "Pedie" and and then update username and date?
I know this can be very easy for you guys, I need to know how update things works here.

like in excel example..

Code:
[/FONT]
[FONT=Courier New]Sheet1.activate[/FONT]
[FONT=Courier New]range("A1").value = Username.value[/FONT]
[FONT=Courier New]range("B1").value = Date.value[/FONT]
[FONT=Courier New]

Thanks agan for helping.:)
 
Upvote 0
NZ() is explained in Access help - in short, if a value is Null it will substitute a default value of "" for the Null.

NZ(Null) --> returns ""
NZ(Null, 0) --> returns 0
NZ(Null, "Mary Poppins") --> returns "Mary Poppins"

If the value passed to NZ is not Null, it remains as it is:
NZ("Pedie","Mary Poppins") --> returns "Pedie"

Updating a table can be done in many different ways. If the control is bound to the table (simplest) then changes are immediate and automatic. The only trouble here is sometimes updates occur when you don't expect them. I like to (suggest to) make all fields required. So nothing can ever be committed to a table unless it is a complete entry with all fields filled in.
 
Upvote 0
Xen, thanks for explaining things in detail.
About update table, I want to try on the code and not by using the query.

how can i make my code refer to table or records and fields...Please give me a start.


is it something like this?
Code:
[/FONT]
[FONT=Courier New] table("Pedie").Usernames.value = Forms("MyForm").Username.value[/FONT]
[FONT=Courier New]


Thanks again.


And is there a site or sample codes i can refer to?
 
Upvote 0
It depends - do you want to Add a new record or Change (update) an existing record?

(It's better to learn Access without code at first ... forces you to learn how Access works and saves you from writing so much code in the long run. That said, you can write SQL scripts or use DAO recordsets to work with your data in tables and forms).
 
Upvote 0
Upvote 0
Xen, I am still going through it...very interesting this is type of code examples i need. Thank you soo very much!!!:)


Just tried this code and works perfect!

Hey Xenou, I am not getting the example of how to update it in different database. Suppose i have a form in database1 and want to add the records to database2 then how is this achieved?

I know I have asked to many things but if you have time, please help me with this one too.


Thanks again soo much!:)
Code:
[/FONT]
[FONT=Courier New]Option Compare Database
Option Explicit[/FONT]
[FONT=Courier New]Sub TryLoop()
Dim rs As DAO.Recordset
Dim ID As Object
Dim LN As Object
' open the DAO or ADO recordsets as shown above (Workstations only)[/FONT]
[FONT=Courier New]Set rs = CurrentDb.OpenRecordset("MyTable", dbOpenDynaset)[/FONT]

[FONT=Courier New]Set ID = rs("Names") ' open the object container for these fields
Set LN = rs("Dates")[/FONT]
[FONT=Courier New]Do While Not rs.EOF
    Debug.Print ID; LN ' compare this syntax to the usual syntax in the example below
    rs.MoveNext
Loop
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,558
Messages
6,179,512
Members
452,921
Latest member
BBQKING

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top