User Name * Computer Name...

L

ldiaz

Hi I'm using this code to get UserName and ComputerName of all user that
access to my DataBase.

this code is in the Form, also I have two modules named: fOSMachineName and
fOSUserName , the codes of these modules wre copied from www.mvps.org but I
don't know why it does not work,

could you help me, I will appreciate so much

ldiaz

______________________________________________
Option Compare Database

Private Sub form_Open(Cancel As Integer)


On Error GoTo ErrHandler


DoCmd.GoToRecord acDataForm, Me.Form, acNewRec

Me!UserName.Text = fOSUserName()
Me!ComputerName.Value = fOSMachineName()
Me!BeginTime.Value = Now()
RunCommand acCmdSaveRecord

Exit Sub

ErrHandler:

MsgBox "Error in Form_Open( ) in" & vbCrLf & _
Me.Name & " form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
Err.Clear

End Sub


Private Sub form_Timer()

On Error GoTo ErrHandler

Me.Visible = False
Me.TimerInterval = 0

Exit Sub

ErrHandler:

MsgBox "Error in Form_Timer( ) in" & vbCrLf & _
Me.Name & " form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
Err.Clear

End Sub


Private Sub form_Unload(Cancel As Integer)

On Error GoTo ErrHandler

Me!EndTime.Value = Now()

Exit Sub

ErrHandler:

If (Err.Number = 2448) Then
' Ignore, since the form is going into Design View.
Else
MsgBox "Error in Form_Unload( ) in" & vbCrLf & _
Me.Name & " form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
End If

Err.Clear

End Sub
 
D

Douglas J Steele

Rename your modules. Modules cannot be named the same as functions or subs
that are contained within them.
 
D

Dirk Goldgar

ldiaz said:
Hi I'm using this code to get UserName and ComputerName of all user
that access to my DataBase.

this code is in the Form, also I have two modules named:
fOSMachineName and fOSUserName , the codes of these modules wre
copied from www.mvps.org but I don't know why it does not work,

could you help me, I will appreciate so much

ldiaz

______________________________________________
Option Compare Database

Private Sub form_Open(Cancel As Integer)


On Error GoTo ErrHandler


DoCmd.GoToRecord acDataForm, Me.Form, acNewRec

Me!UserName.Text = fOSUserName()
Me!ComputerName.Value = fOSMachineName()
Me!BeginTime.Value = Now()
RunCommand acCmdSaveRecord

Exit Sub

ErrHandler:

MsgBox "Error in Form_Open( ) in" & vbCrLf & _
Me.Name & " form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
Err.Clear

End Sub


Private Sub form_Timer()

On Error GoTo ErrHandler

Me.Visible = False
Me.TimerInterval = 0

Exit Sub

ErrHandler:

MsgBox "Error in Form_Timer( ) in" & vbCrLf & _
Me.Name & " form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
Err.Clear

End Sub


Private Sub form_Unload(Cancel As Integer)

On Error GoTo ErrHandler

Me!EndTime.Value = Now()

Exit Sub

ErrHandler:

If (Err.Number = 2448) Then
' Ignore, since the form is going into Design View.
Else
MsgBox "Error in Form_Unload( ) in" & vbCrLf & _
Me.Name & " form." & vbCrLf & vbCrLf & _
"Error #" & Err.Number & vbCrLf & vbCrLf & Err.Description
End If

Err.Clear

End Sub

This line:
Me!UserName.Text = fOSUserName()

should certainly be using the Value property, not the Text property:

Me!UserName.Value = fOSUserName()

Aside from that, I'm not sure that you'll be able to assign values to
bound controls on the form during the form's Open event, or during the
form's Unload event. I recall that being a problem in other situations,
but I gather you got this code originally from Gunny ('69 Camaro), who
is usually reliable. What error message are you getting? If you aren't
getting an error message, in what way does it "not work"?
 
L

ldiaz

I have renamed the modules names to fOSMachineName1 and fOSUserName1 , also I
have changed UserName.text to UserName.value , I got this error:

"Error in Form_Open()in
Error#2498
an expression you entered is the worng data type for one of the arguments"


I have checked step by step all my expresions and are ok.

could you help me, I'll appreciate so much.

God Bless.
ldiaz
 
D

Dirk Goldgar

ldiaz said:
I have renamed the modules names to fOSMachineName1 and fOSUserName1
, also I have changed UserName.text to UserName.value , I got this
error:

"Error in Form_Open()in
Error#2498
an expression you entered is the worng data type for one of the
arguments"


I have checked step by step all my expresions and are ok.

could you help me, I'll appreciate so much.

Sorry for this very late reply.

Are UserName and ComputerName bound controls? Are they text boxes, or
some other type of control? If they are bound controls, what are the
data types of the fields they are bound to?
 
D

Dirk Goldgar

ldiaz said:
Yes, these are Textbox, could you check please.

I just spotted the error in your code. This line is incorrect:
DoCmd.GoToRecord acDataForm, Me.Form, acNewRec

It should be:

DoCmd.GoToRecord acDataForm, Me.Name, acNewRec
 
L

ldiaz

Dear GoldGar...

this code work very fine, thank for your help..
'
I'm happy with your answer.

Ldiaz
 

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