EDrror only on MDE

khwaja

Registered User.
Local time
Tomorrow, 08:18
Joined
Jun 13, 2003
Messages
254
Error only on MDE

I have a MDB file and it works fine. Debugged it. No issues. but when I create a mde, I get the attached error (The expression on load you entered....) Not too sure how to get rid of this. It is quite intermittent as sometimes I don't get it. It appears right at the start.
 

Attachments

  • Error.JPG
    Error.JPG
    23.7 KB · Views: 75
Last edited:
Can you post/show us the code associated with the OnLoad event?
 
Thanks. Apologies for the garbled subject. Following is the code"

Private Sub Form_Load()
Dim rec As DAO.Recordset
Set rec = CurrentDb.OpenRecordset("tblUser", dbOpenDynaset)

With rec
.AddNew
!Loginid = fOSUserName
!Dated = Now
.Update
.Close
End With
Set rec = Nothing
'MsgBox "Design Status for Construction updated successfully."

End Sub
 
What is the error message and code?
What is fOSUserName? and how is it Dimmed? ((should it be fsoUserName ---just a guess))
Do you know how to step debug? see the debugging tips in my signature
 
Last edited:
Thanks. I have attached the error message once. again. There is no code associated. The code referring to fOSUserName is as under:

Function fOSUserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If lngX <> 0 Then
fOSUserName = Left$(strUserName, lngLen - 1)
Else
fOSUserName = ""
End If
End Function

I will do the debugging in the meanwhile.
 
No issues with the debugging of FODUserName when I debugged. But not too sure how you debug form_load code. It does nothing when I press F8.
 
Last edited:
Thanks. This application starts with a copyright notice with code on the Form_Load I sent earlier. It has following additional code on the same form:

Private Sub Form_Open(Cancel As Integer)
Application.SetOption "ShowWindowsInTaskbar", False
End Sub

Private Sub Form_Timer()
' Form stays open for 5 seconds, then closes...
DoCmd.Close acForm, Me.Name
' .. and opens the signon form
DoCmd.OpenForm "Switchboard"
End Sub

After this an invisible form opens to keep time elapsed and close the application with the following code:

Private Sub Form_Timer()

' IDLEMINUTES determines how much idle time to wait for before
' running the IdleTimeDetected subroutine.
Const IDLEMINUTES = 40

Static PrevControlName As String
Static PrevFormName As String
Static ExpiredTime

Dim ActiveFormName As String
Dim ActiveControlName As String
Dim ExpiredMinutes

On Error Resume Next

' Get the active form and control name.

ActiveFormName = Screen.ActiveForm.Name
If err Then
ActiveFormName = "No Active Form"
err = 0
End If

ActiveControlName = Screen.ActiveControl.Name
If err Then
ActiveControlName = "No Active Control"
err = 0
End If

' Record the current active names and reset ExpiredTime if:
' 1. They have not been recorded yet (code is running
' for the first time).
' 2. The previous names are different than the current ones
' (the user has done something different during the timer
' interval).
If (PrevControlName = "") Or (PrevFormName = "") _
Or (ActiveFormName <> PrevFormName) _
Or (ActiveControlName <> PrevControlName) Then
PrevControlName = ActiveControlName
PrevFormName = ActiveFormName
ExpiredTime = 0
Else
' ...otherwise the user was idle during the time interval, so
' increment the total expired time.
ExpiredTime = ExpiredTime + Me.TimerInterval
End If

' Does the total expired time exceed the IDLEMINUTES?
ExpiredMinutes = (ExpiredTime / 1000) / 55
If ExpiredMinutes >= IDLEMINUTES Then
' ...if so, then reset the expired time to zero...
ExpiredTime = 0
' ...and call the IdleTimeDetected subroutine.
IdleTimeDetected ExpiredMinutes
End If
End Sub



Sub IdleTimeDetected(ExpiredMinutes)

'Dim Msg As String
'Msg = "No user activity detected in the last "
'Msg = Msg & ExpiredMinutes & " minute(s)!"
'MsgBox Msg, 48
Application.Quit A_SAVE
End Sub

In addition, I have an auto exec macro which fires off the following code:

Function InitApplication()
Dim C As CloseCommand
Set C = New CloseCommand

'Disable Close menu.
C.Enabled = False
End Function
 
I may have found the reason. It is the copyright form with Form Load code causing the issue. The run time error is 3022. I have attached a screenshot. It is stopping at .Update line. I am not too sure what is the issue as there is user table which captures user id and time and I have not made changes to this table. The only change I did was to recently password protect the backend and re linked all tables.
 

Attachments

  • Error.JPG
    Error.JPG
    23.5 KB · Views: 92
So you stepped through the code. On what line did the OnLoad error occur.
Let's focus on the error you reported in post 1.

OOOps: You posted while I was writing. A 3022 error is trying to save or place a duplicate value for a field which has "Allow Duplicates" = NO, or an attempt to add a duplicate PK etc.

Note: This is a different error than the one you had in post 1.
 
Last edited:
Thanks. I have checked the PK and there are no duplicates. The User login field can have duplicates. So at loss to understand what needs to be done to remove the error. Following is the structure of the table.


UserID - Auto - Yes (No Duplicates)
LoginID - Text - Yes (Duplicates OK)
Dated - Date
 
No there won't be duplicates. The message says you were trying to add a duplicate (3022).
You can use an error handler to trap the 3022, then take what ever action you want.

I'd add some Debug.Print statements to show the values of some fields to see if there is some value/condition that you weren't expecting--then find the cause/investigate.
 
A big thank you for persevering with me. Turned out that the table was not creating unique auto ID. I have recreated the table and it now works. Much appreciate your time and advice.
 
Happy to help.
Good luck with your projects.
 

Users who are viewing this thread

Back
Top Bottom