What have i done wrong ? Runtime Error 94 invalid use of null

G

Guest

I'm very new to this coding business, but with the help of these pages have
managed to concoct the code below.

Myname = Me.Text0
If IsNull(Me.Text0) Then
MsgBox "Enter Initials"
Else
DoCmd.OpenForm "Loginformdata", , , , , acHidden
DoCmd.GoToRecord acForm, "Loginformdata", acNewRec
Forms!loginformdata![UserName] = Myname
DoCmd.Close acForm, "Loginformdata"
DoCmd.Close acForm, "Login box"
MsgBox "Welcome to The Contractor Database"
DoCmd.OpenForm "switchboard"
End Sub

I have a table called Usergroups
A form with 3 fields (username, date, time) which updates the table called
"Loginformdata",
Another form with a textbox (text0) and a command button2
The above code is on the command button - on click

What i want to happen is on starting the DB, user enter's their initials,
and the table is updated with initials date/time. This works fine.
If they don't enter anything in the text box, and then presses the command
button it all falls over and the debugger starts at the line "Myname =
Me.Text0"

What have I done wrong??? Please help!
 
S

Stefan Hoffmann

hi,

just obey the order.

Sarella wrote:

If Len(Trim(Nz(Me.Text0, ""))) = 0 Then
MsgBox "Enter Initials"
Else MyName = Me.Text0
DoCmd.OpenForm "Loginformdata", , , , , acHidden
DoCmd.GoToRecord acForm, "Loginformdata", acNewRec
Forms!loginformdata![UserName] = Myname
DoCmd.Close acForm, "Loginformdata"
DoCmd.Close acForm, "Login box"
MsgBox "Welcome to The Contractor Database"
DoCmd.OpenForm "switchboard"
End Sub




mfG
--> stefan <--
 
G

Guest

You are an absolute star - thank you so much

Stefan Hoffmann said:
hi,

just obey the order.

Sarella wrote:

If Len(Trim(Nz(Me.Text0, ""))) = 0 Then
MsgBox "Enter Initials"
Else MyName = Me.Text0
DoCmd.OpenForm "Loginformdata", , , , , acHidden
DoCmd.GoToRecord acForm, "Loginformdata", acNewRec
Forms!loginformdata![UserName] = Myname
DoCmd.Close acForm, "Loginformdata"
DoCmd.Close acForm, "Login box"
MsgBox "Welcome to The Contractor Database"
DoCmd.OpenForm "switchboard"
End Sub




mfG
--> stefan <--
 
G

Guest

Hi Stefan, As you guessed from my previous post, the code you gave me was
did exactly what i was after.
I've inserted the code, and saved everything, but now when i exit access, i
get an errormessage saying "could not find field 'description'"
This didn't happen prior to adding this bit of code - any ideas?

Stefan Hoffmann said:
hi,

just obey the order.

Sarella wrote:

If Len(Trim(Nz(Me.Text0, ""))) = 0 Then
MsgBox "Enter Initials"
Else MyName = Me.Text0
DoCmd.OpenForm "Loginformdata", , , , , acHidden
DoCmd.GoToRecord acForm, "Loginformdata", acNewRec
Forms!loginformdata![UserName] = Myname
DoCmd.Close acForm, "Loginformdata"
DoCmd.Close acForm, "Login box"
MsgBox "Welcome to The Contractor Database"
DoCmd.OpenForm "switchboard"
End Sub




mfG
--> stefan <--
 
S

Stefan Hoffmann

hi,
Hi Stefan, As you guessed from my previous post, the code you gave me was
did exactly what i was after.
I've inserted the code, and saved everything, but now when i exit access, i
get an errormessage saying "could not find field 'description'"
This didn't happen prior to adding this bit of code - any ideas?
Nope. Don't see any field called like that. To which tables does it belong?

If Len(Trim(Nz(Me.Text0, ""))) = 0 Then
MsgBox "Enter Initials"
Else MyName = Me.Text0
DoCmd.OpenForm "Loginformdata", , , , , acHidden
DoCmd.GoToRecord acForm, "Loginformdata", acNewRec
Forms!loginformdata![UserName] = Myname
DoCmd.Close acForm, "Loginformdata"
DoCmd.Close acForm, "Login box"
MsgBox "Welcome to The Contractor Database"
DoCmd.OpenForm "switchboard"
End Sub
Instead of using a hidden form to save your data, you can use

CurrentDb.Execute "INSERT INTO LoginTable (Username, LoginTime) " & _
"VALUES ('" & Replace(Myname, "'", "''")& "',
Now())", dbFailOnError


mfG
--> stefan <--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top