Results 1 to 5 of 5
  1. #1
    blanic is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2015
    Posts
    2

    Active Directory/MS Access ISSUE

    My question is how do I fix the following issue:
    All of the fields i have no issue with getting the information other than the "ACCOUNTEXPIRES" field. It is because it does not convert correctly or i have a bad setting. The following URL is something i tried, even modifiying with my limited ability but could not get it to work. http://www.rlmueller.net/Integer8Attributes.htm
    If there is a way to take what is in that link to convert that field to the correct date (ACCOUNTEXPIRES) that is what I am trying to do. The other fields work as intended, please do not let the other code throw you it all works. I hope that better helps to what i am doing. Like i said the other fields work with no issues, it is the one field that is causing me this problem. Thanks again.
    strOU1=LDAP://OU=TEST,DC=Test,DC=TEST,DC=TEST,DC=TEST


    Set objConnection = CreateObject("ADODB.Connection")
    Set objCommand = CreateObject("ADODB.Command")
    objConnection.Provider = "ADsDSOObject"
    objConnection.Open "Active Directory Provider"
    Set objCommand.ActiveConnection = objConnection
    objCommand.Properties("Page Size") = 1000
    objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
    objCommand.Properties("Chase referrals") = ADS_CHASE_REFERRALS_EXTERNAL
    objCommand.CommandText = "SELECT givenName, sn, name, department, title, sAMAccountName, accountExpires, userAccountControl FROM '" & strOU1 & "' WHERE objectCategory='user' ORDER BY sAMAccountName"
    Set objRecordset = objCommand.Execute
    While Not objRecordset.EOF
    Set strName = objRecordset.Fields("Name")
    strName = Replace(strName, "'", "''")
    Set strDept = objRecordset.Fields("department")
    Set stradname = objRecordset.Fields("sAMAccountName")
    Set strExp = objRecordset.Fields("accountExpires").Value
    'Set strExp = objRecordset.Fields("accountExpires") 'I have tried this as well in place of the above
    CurrentDb.Execute "Insert Into Test (Tname,adname,dept,exp) Values ( '" & strName & "', '" & stradname & "', '" & strDept & "', '" & strExp & "')", dbFailOnError
    objRecordset.MoveNext
    Wend

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Try using # delimiter for date parameter instead of apostrophe in the INSERT sql.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    blanic is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2015
    Posts
    2
    it fails before it gets there, it fails on strEXP

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    What is the error message?

    "Set" is not needed when populating simple variables. Another way to reference fields of recordset uses the ! (bang) character.

    strExp = objRecordset!accountExpires

    I don't see declarations for these variables. If they are not declared then they will default to Variant type which should accept any data. If strExp has been declared as a string type then this could cause a conflict if trying to populate with a date value.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by June7 View Post
    ...I don't see declarations for these variables....
    @blanic
    This seems to be part of your issue, at least. You should be explicit with your variable types. Also, what kind of DB are you updating/appending? Date types in Access are not necessarily compatible with other RDBMS.

    Maybe revisit June's suggestion of using the hashtag delimiter after you get the correct variable declaration.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 7
    Last Post: 04-19-2024, 04:06 PM
  2. Access and Active Directory...
    By Voodeux2014 in forum Access
    Replies: 4
    Last Post: 01-19-2015, 02:31 PM
  3. Incorporating active directory with Access
    By ajknoll23 in forum Security
    Replies: 4
    Last Post: 04-29-2014, 08:13 AM
  4. Replies: 1
    Last Post: 01-11-2014, 12:39 PM
  5. access+Active directory
    By cpcp in forum Access
    Replies: 6
    Last Post: 11-15-2010, 02:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums