[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Access 2007 - Reserved Error (-1524)

Posted on 2009-12-29
16
Medium Priority
?
576 Views
Last Modified: 2013-11-27
This is very hard to explain, please bear with me...

I am opening an Access 2003 database with newly deployed Access 2007 software.  Access 2007 seems to work very well with our 2003 database, except for one particular item I cannot figure out.  We use this database to generate purchase orders, and when a new purchase order is created I have a VB module that gets the current users full name from the Domain and creates the record for the new PO and them opens the PO form to be filled in.  I have discovered that when I try to write the user name to the record set the following error results:

      "Reserved error (-1524); there is no message for this error."

To get the user name I am using the module "fGetFullNameOfLoggedUser()" that I found here on the exchange.  The module is working properly and returns a sting of the user name.

Important notes: When I run the same script in the older access 2003 software, it runs without any errors.  I have searched the associated table for any corruption, and cannot find any.  I have also run the compact and repair.

During my debugging of this problem I discovered a couple interesting things:
1)  When I set a variable 'DebugUserName = fGetFullNameOfLoggedUser()' it returns the correct user name sting in the Locals window.
2)  When the code hits the line 'MyRS![UserName] = DebugUserName"'it results in the error.
3)  If I manually set the variable with the same string 'DebugUserName = "John Doe"' the module works and writes the string to the table without any errors.

Here is the module that I am having the problem, (it includes my DEBUG entries)...
Note: I have attached the code for the fGetFullNameOfLoggedUser() function as a code snippet.
-------------------------------------------------------------------------------------------------------------------
Private Sub btnOK_Click()
' Error handler
    On Error GoTo Err_btnOK_Click
   
    Dim MyDB As DAO.Database
    Dim MyRS As DAO.Recordset
    Dim POID As Integer
    Dim ProjectID As Double
    Dim JobNumber As String
    Dim LastPONumber As Integer
    Dim NewPONumber As Integer
    Dim NewPO As String
    Dim PONumberID As Integer
    Dim POType As Integer
    Dim stDocName As String
    Dim stLinkCriteria As String
   
    POType = Me.frameSelectPOType
   
'Get ProjectID and Job Number
    Set MyDB = CurrentDb
    Set MyRS = MyDB.OpenRecordset("qryJob-mod")
    ProjectID = MyRS![ProjectID]
    JobNumber = MyRS![JobNumber]
    MyRS.Close
    Set MyRS = MyDB.OpenRecordset("qryPONumber-frm")
    If MyRS.BOF And MyRS.EOF Then
        LastPONumber = 0
    Else
        MyRS.MoveLast
        LastPONumber = MyRS![Number]
    End If
'Set new PO Number
    NewPONumber = LastPONumber + 1
'Adding the new PO to the record set
    MyRS.AddNew
    MyRS![ProjectID] = ProjectID
    MyRS![Number] = NewPONumber
    PONumberID = MyRS![PONumberID]
    MyRS.Update
'Get the new PONumberID
    'MyRS.MoveLast
    'PONumberID = MyRS![PONumberID]
    MyRS.Close

    Set MyRS = MyDB.OpenRecordset("tblPO", dbOpenDynaset)
    MyRS.AddNew
    MyRS![PONumberID] = PONumberID
    MyRS![Date] = Date
    MyRS![BillOfMaterialTypeID] = POType
   
    'DEBUGGING START
    Dim DebugUserName As String
    DebugUserName = fGetFullNameOfLoggedUser()
    'DebugUserName = "John Doe"                    'Used for debugging
    Stop                                              'DEBUG STOP
    MyRS![UserName] = DebugUserName            '<<<<<<<<<<ERROR OCCURS HERE
   
    Select Case POType
        Case 1
        MyRS![VendorID] = 5                        'Default to Alcan
        MyRS![VendorSalesContactID] = 6               'Defualt to Dyane Poynor
        stDocName = "frmPO - ACM"
       
        Case 6
        MyRS![VendorID] = 19                        'Default to Sapa
        MyRS![VendorSalesContactID] = 22               'Defualt to Lisa Leis
        stDocName = "frmPO - Extrusions"
       
        Case Else
        stDocName = "frmPO"
    End Select

    POID = MyRS![POID]
    MyRS.Update
   
    stLinkCriteria = "[POID]=" & POID
    DoCmd.OpenForm stDocName, , , stLinkCriteria
    DoCmd.Close acForm, "frmPONew" 'Close New PO Form
   
Exit_btnOK_Click:
    Exit Sub
Err_btnOK_Click:
    MsgBox Err.Description
    Resume Exit_btnOK_Click
End Sub

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

I have attached the code for the fGetFullNameOfLoggedUser() Function
Option Compare Database
Option Explicit

'This code was originally written by Dev Ashish.
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
'Code Courtesy of
'Dev Ashish
'
Private Type USER_INFO_2
    usri2_name As Long
    usri2_password  As Long  ' Null, only settable
    usri2_password_age  As Long
    usri2_priv  As Long
    usri2_home_dir  As Long
    usri2_comment  As Long
    usri2_flags  As Long
    usri2_script_path  As Long
    usri2_auth_flags  As Long
    usri2_full_name As Long
    usri2_usr_comment  As Long
    usri2_parms  As Long
    usri2_workstations  As Long
    usri2_last_logon  As Long
    usri2_last_logoff  As Long
    usri2_acct_expires  As Long
    usri2_max_storage  As Long
    usri2_units_per_week  As Long
    usri2_logon_hours  As Long
    usri2_bad_pw_count  As Long
    usri2_num_logons  As Long
    usri2_logon_server  As Long
    usri2_country_code  As Long
    usri2_code_page  As Long
End Type
 
Private Declare Function apiNetGetDCName _
    Lib "netapi32.dll" Alias "NetGetDCName" _
    (ByVal servername As Long, _
    ByVal DomainName As Long, _
    bufptr As Long) As Long
 
' function frees the memory that the NetApiBufferAllocate
' function allocates.
Private Declare Function apiNetAPIBufferFree _
    Lib "netapi32.dll" Alias "NetApiBufferFree" _
    (ByVal buffer As Long) _
    As Long
 
' Retrieves the length of the specified wide string.
Private Declare Function apilstrlenW _
    Lib "kernel32" Alias "lstrlenW" _
    (ByVal lpString As Long) _
    As Long
 
Private Declare Function apiNetUserGetInfo _
    Lib "netapi32.dll" Alias "NetUserGetInfo" _
    (servername As Any, _
    UserName As Any, _
    ByVal level As Long, _
    bufptr As Long) As Long
 
' moves memory either forward or backward, aligned or unaligned,
' in 4-byte blocks, followed by any remaining bytes
Private Declare Sub sapiCopyMem _
    Lib "kernel32" Alias "RtlMoveMemory" _
    (Destination As Any, _
    Source As Any, _
    ByVal Length As Long)
 
Private Declare Function apiGetUserName Lib _
    "advapi32.dll" Alias "GetUserNameA" _
    (ByVal lpBuffer As String, _
    nSize As Long) _
    As Long
 
Private Const MAXCOMMENTSZ = 256
Private Const NERR_SUCCESS = 0
Private Const ERROR_MORE_DATA = 234&
Private Const MAX_CHUNK = 25
Private Const ERROR_SUCCESS = 0&
 
Function fGetFullNameOfLoggedUser(Optional strUserName As String) As String
'
' Returns the full name for a given UserID
'   NT/2000 only
' Omitting the strUserName argument will try and
' retrieve the full name for the currently logged on user
'
On Error GoTo ErrHandler
Dim pBuf As Long
Dim dwRec As Long
Dim pTmp As USER_INFO_2
Dim abytPDCName() As Byte
Dim abytUserName() As Byte
Dim lngRet As Long
Dim i As Long
 
    ' Unicode
    abytPDCName = fGetDCName() & vbNullChar
    If (Len(strUserName) = 0) Then strUserName = fGetUserName()
    abytUserName = strUserName & vbNullChar
 
    ' Level 2
    lngRet = apiNetUserGetInfo( _
                            abytPDCName(0), _
                            abytUserName(0), _
                            2, _
                            pBuf)
    If (lngRet = ERROR_SUCCESS) Then
        Call sapiCopyMem(pTmp, ByVal pBuf, Len(pTmp))
        fGetFullNameOfLoggedUser = fStrFromPtrW(pTmp.usri2_full_name)
    End If
 
    Call apiNetAPIBufferFree(pBuf)
ExitHere:
    Exit Function
ErrHandler:
    fGetFullNameOfLoggedUser = vbNullString
    Resume ExitHere
End Function
 
Function fGetUserName() As String
' Returns the network login name
Dim lngLen As Long, lngRet As Long
Dim strUserName As String
    strUserName = String$(254, 0)
    lngLen = 255
    lngRet = apiGetUserName(strUserName, lngLen)
    If lngRet Then
        fGetUserName = Left$(strUserName, lngLen - 1)
    End If
End Function
 
Function fGetDCName() As String
Dim pTmp As Long
Dim lngRet As Long
Dim abytBuf() As Byte
 
    lngRet = apiNetGetDCName(0, 0, pTmp)
    If lngRet = NERR_SUCCESS Then
        fGetDCName = fStrFromPtrW(pTmp)
    End If
    Call apiNetAPIBufferFree(pTmp)
End Function
 
Private Function fStrFromPtrW(pBuf As Long) As String
Dim lngLen As Long
Dim abytBuf() As Byte
 
    ' Get the length of the string at the memory location
    lngLen = apilstrlenW(pBuf) * 2
    ' if it's not a ZLS
    If lngLen Then
        ReDim abytBuf(lngLen)
        ' then copy the memory contents
        ' into a temp buffer
        Call sapiCopyMem( _
                abytBuf(0), _
                ByVal pBuf, _
                lngLen)
        ' return the buffer
        fStrFromPtrW = abytBuf
    End If
End Function

Open in new window

0
Comment
Question by:shrimpfork
  • 9
  • 5
  • 2
16 Comments
 
LVL 85
ID: 26140082
Try using this syntax:

MyRS("UserName") = DebugUserName

0
 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 26140441
try changing this
                DebugUserName = fGetFullNameOfLoggedUser()
to this:
                DebugUserName = CStr(fGetFullNameOfLoggedUser())
 
0
 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 26140802
ps
if CStr didn't fix, try Eval instead:
= Eval(fGetFullNameOfLoggedUser())
 
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:shrimpfork
ID: 26141177
LSMConsulting,
Changing the code to:   MyRS("UserName") = DebugUserName
results in an compile error when I compile the code.
0
 

Author Comment

by:shrimpfork
ID: 26141203
puppydogbuddy,
I have already tried the CStr comand earlier.  I just tried the Eval() suggestion and it returns the following...

"Project Tracker can't find the name 'Jed' you entered in the expression."

(Where Jed is my name and "Project Tracker is the name if the database.)

-Jed
0
 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 26141360
oops, my mistake, the functiion name should be enclosed in double quotes.  see this link:
                 http://msdn.microsoft.com/en-us/library/aa172212(office.11).aspx

        = Eval("fGetFullNameOfLoggedUser()")

                       
0
 

Author Comment

by:shrimpfork
ID: 26141493
puppydogbuddy,
I applied the Eval("fGetFullNameOfLoggedUser()") and it reults in the original reserved error (-1524).
This is interesting.  I tried the folowing:
    DebugUserName = fGetFullNameOfLoggedUser()
    DebugUserName = Left(DebugUserName, 12)
    MyRS![UserName] = DebugUserName
Where my full name is 12 characters including a space and it worked without any errors.  I wonder if the original string created by the fGetFullNameOfLoggedUser() includes some hidden character that I can not see in the LOCALS window.

 
0
 

Author Comment

by:shrimpfork
ID: 26141525
Adding to my previous comment, I also tried the following:

   DebugUserName = fGetFullNameOfLoggedUser()
   DebugUserName = Left(DebugUserName, 13)
   MyRS![UserName] = DebugUserName

Where my name is only 12 characters and the Left function called for 13 characters.  It resulted in the same reserverd error (-1524) when it tried to write the string to the record set.  Is the problem caused by a blank space on the end of the name or something?
0
 
LVL 38

Accepted Solution

by:
puppydogbuddy earned 2000 total points
ID: 26141587
could be ....try using the Trim function
     DebugUserName = Trim(fGetFullNameOfLoggedUser())
0
 

Author Comment

by:shrimpfork
ID: 26141689
The trim function worked!!!  I also put in a variable to give me the length of the string.  It resulted in 12  for my name which is correct.  So there is nothing on the end of the string.  This is very strange.
0
 

Author Comment

by:shrimpfork
ID: 26141707
puppydogbuddy,
The trim function appears to be a good patch for the problem.  I would like to know the root fo the cause of the error.  Any thought on this?
-Jed
0
 
LVL 38

Expert Comment

by:puppydogbuddy
ID: 26141788
The trim function removes beginning and/or trailing spaces from the string so that they are not included in the evaluation of the string.   So, it appears that somehow the function you are using allows a beginning and/or ending space in the output string.  if you look at lines 102 thru 105 of the function code, a vbNullcharacter appears to be added to the end of the string for unicode???
0
 

Author Comment

by:shrimpfork
ID: 26141827
puppydogbuddy,
That makes sense.  I am new to the 2007 version, and I remember that 2003 automatically took care of blank characters at the end of entered text fields.  Does 2007 behave the same way?
0
 
LVL 85
ID: 26142090
But why would a Null value or empty string cause this to fail? That doesn't make sense.

Also:

MyRS("UserName")

is exactly identical to

MyRs![UserName]

Access actually converts the second to the first "under the covers" ... so I'm not sure why you would get a compile error on this. Makes me think something else is going on here.

Also, there are known issues when trying to run a db created in 2003 in 2007. The "fix" is to build a new, blank db in 2007 (using the older format) and import everything into that new container.
0
 

Author Comment

by:shrimpfork
ID: 26142157
LSMConsulting,
My mistake...I had it as MyRS!("UserName"), which was not correct.  I just tested it and It did compile.

My next step was to convert this database to 2007, but I was wondering if it would be better to import it into a 2007 database instead.  The security is my biggest hurtle.  I was going to post this as a separate question.
-Jed
0
 

Author Comment

by:shrimpfork
ID: 26142171
LSMConsulting,
PS:  The line MyRS("UserName") = fGetFullNameOfLoggedUser() returned the same erorr (-1524).
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
This article shows how to get a list of available printers for display in a drop-down list, and then to use the selected printer to print an Access report or a Word document filled with Access data, using different syntax as needed for working with …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question