drtopserv
asked on
LDAP
Hi,
I have a code attached that is not working in my access vba .
may plz modify the code to get it work.
i need to do this:
I need to provide a ID in txtbox in a form and then perform a check in LDAP .
if this ID = SerialNumber" property in LDAP then msgbox "Found"
I have a code attached that is not working in my access vba .
may plz modify the code to get it work.
i need to do this:
I need to provide a ID in txtbox in a form and then perform a check in LDAP .
if this ID = SerialNumber" property in LDAP then msgbox "Found"
ASKER
LSMConsulting, first i`m glad that u helped me out many times:} around.
well, i have wrote in bold what i`m trying to do ,but still no luck;}
i need away to connect to ldap and retrieve "SerialName" property from it.
i search the expert-exchange and found the code that i attached ,but i can`t figure out how to let it work, at this time the gives me error GetProperty variable not define.
should i add specfic reference to let it work?
or how can i perform the task?
well, i have wrote in bold what i`m trying to do ,but still no luck;}
i need away to connect to ldap and retrieve "SerialName" property from it.
i search the expert-exchange and found the code that i attached ,but i can`t figure out how to let it work, at this time the gives me error GetProperty variable not define.
should i add specfic reference to let it work?
or how can i perform the task?
ASKER
sorry, not "Serialname" BUT "SerialNumber" property
You didn't attach your code to the question. Could you upload it?
ASKER
Private Sub txtConsultantName_BeforeUp date(Cance l As Integer)
Stop
Dim TempYoetzFirstName As String
Dim YoetzFirstName As String
Dim TempYoetzLastName As String
Dim YoetzLastName As String
TempYoetzFirstName = txtConsultantName.Value
If InStr(1, TempYoetzFirstName, " ") = 0 Then
MsgBox "! çåáä ìäæéï ùí îùôçä + ùí ôøèé", vbCritical + vbMsgBoxRight, "ùâéàä"
Cancel = True
Exit Sub
End If
YoetzFirstName = Left(TempYoetzFirstName, (InStr(TempYoetzFirstName, " ") - 1))
'MsgBox YoetzFirstName
TempYoetzLastName = txtConsultantName.Value
YoetzLastName = Right(TempYoetzLastName, (Len(TempYoetzLastName) - (InStr(TempYoetzLastName, " "))))
'MsgBox YoetzLastName
Dim strFilter: strFilter = "(&(givenname=" & YoetzFirstName & ") (sn=" & YoetzLastName & "))"
'Dim strFilter: strFilter = "(&(givenname=øåðéú) (sn=ãéðø))"
'MsgBox strFilter
Dim wscript As AccessObject
Dim objconnection: Set objconnection = CreateObject("ADODB.Connec tion")
objconnection.Provider = "ADsDSOObject"
'objconnection.Open "Active Directory Users and Computers"
objconnection.Open "ADs Provider"
Dim YoezCodeNumber As String
Dim ss As String
Dim SnifNumber As Long
Dim n As Boolean
Dim YoezCount As Long
'WaitWhileRunning (lngHWnd)
Dim objRootDSE: Set objRootDSE = GetObject("LDAP://mydomain /RootDSE")
Dim objRecordSet: Set objRecordSet = objconnection.Execute( _
"<LDAP://" & objRootDSE.Get("dnsHostNam e") & ">;" & _
strFilter & ";distinguishedName,name,s AMAccountN ame,Serial Number,giv enName,sn; subtree")
Set objRootDSE = Nothing
While Not objRecordSet.EOF
' Echoing the distinguished name, just in case
'WScript.Echo objRecordSet.Fields("disti nguishedNa me").Value
' ss = objRecordSet.Fields("disti nguishedNa me").Value
'MsgBox ss
' And the sAMAccountName
' YoezCodeNumber = objRecordSet.Fields("sAMAc countName" ).Value
YoezCodeNumber = objRecordSet.Fields("Seria lNumber"). Value
Debug.Print YoezCodeNumber
Stop
Dim TempYoetzFirstName As String
Dim YoetzFirstName As String
Dim TempYoetzLastName As String
Dim YoetzLastName As String
TempYoetzFirstName = txtConsultantName.Value
If InStr(1, TempYoetzFirstName, " ") = 0 Then
MsgBox "! çåáä ìäæéï ùí îùôçä + ùí ôøèé", vbCritical + vbMsgBoxRight, "ùâéàä"
Cancel = True
Exit Sub
End If
YoetzFirstName = Left(TempYoetzFirstName, (InStr(TempYoetzFirstName,
'MsgBox YoetzFirstName
TempYoetzLastName = txtConsultantName.Value
YoetzLastName = Right(TempYoetzLastName, (Len(TempYoetzLastName) - (InStr(TempYoetzLastName, " "))))
'MsgBox YoetzLastName
Dim strFilter: strFilter = "(&(givenname=" & YoetzFirstName & ") (sn=" & YoetzLastName & "))"
'Dim strFilter: strFilter = "(&(givenname=øåðéú) (sn=ãéðø))"
'MsgBox strFilter
Dim wscript As AccessObject
Dim objconnection: Set objconnection = CreateObject("ADODB.Connec
objconnection.Provider = "ADsDSOObject"
'objconnection.Open "Active Directory Users and Computers"
objconnection.Open "ADs Provider"
Dim YoezCodeNumber As String
Dim ss As String
Dim SnifNumber As Long
Dim n As Boolean
Dim YoezCount As Long
'WaitWhileRunning (lngHWnd)
Dim objRootDSE: Set objRootDSE = GetObject("LDAP://mydomain
Dim objRecordSet: Set objRecordSet = objconnection.Execute( _
"<LDAP://" & objRootDSE.Get("dnsHostNam
strFilter & ";distinguishedName,name,s
Set objRootDSE = Nothing
While Not objRecordSet.EOF
' Echoing the distinguished name, just in case
'WScript.Echo objRecordSet.Fields("disti
' ss = objRecordSet.Fields("disti
'MsgBox ss
' And the sAMAccountName
' YoezCodeNumber = objRecordSet.Fields("sAMAc
YoezCodeNumber = objRecordSet.Fields("Seria
Debug.Print YoezCodeNumber
ASKER
here is a code that works for me for a user property like sAMAccountName for example.
but not for a user attribute SerialNumber.
YoezCodeNumber = objRecordSet.Fields("Seria lNumber"). Value
here it stop with error (run time error 13 - type mismatch) :
Debug.Print YoezCodeNumber
but not for a user attribute SerialNumber.
YoezCodeNumber = objRecordSet.Fields("Seria
here it stop with error (run time error 13 - type mismatch) :
Debug.Print YoezCodeNumber
You could try to convert the number to a string using the cStr() function or the Format(xyz, "0") function
Debug.Print cStr(YoezCodeNumber )
Debug.Print cStr(YoezCodeNumber )
ASKER
sorry it stop in this line :
YoezCodeNumber = objRecordSet.Fields("sAMAc countName" ).Value
run-time error 13-type mismatch
YoezCodeNumber = objRecordSet.Fields("sAMAc
run-time error 13-type mismatch
Either cSTR or Format will solve the problem which is cause because you have declared YoezCodeNumber as a string. You will always get an error when you confuse a number with a string. Cstr will convert the number into a string.
YoezCodeNumber = cStr(objRecordSet.Fields(" sAMAccount Name").Val ue)
YoezCodeNumber = cStr(objRecordSet.Fields("
ASKER
bro ,
this : YoezCodeNumber = objRecordSet.Fields("sAMAccountName").Value works
but
this : YoezCodeNumber = objRecordSet.Fields("SerialNumber ").Value doesn`t
and i need the serialnumber attribute not the sAMAccountName property
this : YoezCodeNumber = objRecordSet.Fields("sAMAccountName").Value works
but
this : YoezCodeNumber = objRecordSet.Fields("SerialNumber ").Value doesn`t
and i need the serialnumber attribute not the sAMAccountName property
The following will work:
YoezCodeNumber = cStr(objRecordSet.Fields("
ASKER
nope this still not working also:}
I tried your code and the error was "invalid use of null", not "type mismatch". Can be fixed by either dim YoezCodeNumber as Variant, or by YoezCodeNumber = nz(objRecordSet.Fields("Se rialNumber ").Value)
ASKER
I hope so,well i can`t check it rght now i should check at work to tomorrow, i`ll post the result until tomorrow .thnx
Yes vadimrapp1 found the correct message "invalid use of null", which is a real pain when handling recordsets.
You may not have a copy of the nz function. I have included some functions that can be useful when handling recordsets.
YoezCodeNumber = Cstr(GitNum(objRecordSet.F ields("Ser ialNumber" ).Value) )
Git() will allow you to transfer a recordset field that has a null value a null value will be converted to a blank string.
GitNum() will do the same but a null value will be converted to a zero.
Hope this helps:~)
Public Function Git(RecordsetField)
' Use this function when accessing ALL DAO/ADO Recordset fields
' To avoide ilegal use of Null error
' Example: MsgBox gf.git(RS("MyField"))
' this function was named after the programmer that thought it would be a good idea to make a program crash because of nothing.
If IsNull(RecordsetField) Then
Git = ""
ElseIf IsEmpty(RecordsetField) Then
Git = ""
Else
Git = RecordsetField
End If
End Function
Public Function GitNum(RecordsetField)
' Force a null field to be numeric
If IsNull(RecordsetField) Or IsEmpty(RecordsetField) Then
GitNum = 0
Else
GitNum = RecordsetField
End If
End Function
You may not have a copy of the nz function. I have included some functions that can be useful when handling recordsets.
YoezCodeNumber = Cstr(GitNum(objRecordSet.F
Git() will allow you to transfer a recordset field that has a null value a null value will be converted to a blank string.
GitNum() will do the same but a null value will be converted to a zero.
Hope this helps:~)
Public Function Git(RecordsetField)
' Use this function when accessing ALL DAO/ADO Recordset fields
' To avoide ilegal use of Null error
' Example: MsgBox gf.git(RS("MyField"))
' this function was named after the programmer that thought it would be a good idea to make a program crash because of nothing.
If IsNull(RecordsetField) Then
Git = ""
ElseIf IsEmpty(RecordsetField) Then
Git = ""
Else
Git = RecordsetField
End If
End Function
Public Function GitNum(RecordsetField)
' Force a null field to be numeric
If IsNull(RecordsetField) Or IsEmpty(RecordsetField) Then
GitNum = 0
Else
GitNum = RecordsetField
End If
End Function
ASKER
Not good , still getting type mismatch :{ 13
Just before this line:
YoezCodeNumber = Cstr(GitNum(objRecordSet.F ields("Ser ialNumber" ).Value) )
Can you insert the following:
MsgBox "VarType=" + Cstr(VarType(objRecordSet. Fields("Se rialNumber ").Value))
When you run the program it will come up with a message box say what the VarType of the recordset element.
If you post back the answer we can have a think about the result.
Alter today I will be at a site with an AD server so I will be able to run the code myself.
YoezCodeNumber = Cstr(GitNum(objRecordSet.F
Can you insert the following:
MsgBox "VarType=" + Cstr(VarType(objRecordSet.
When you run the program it will come up with a message box say what the VarType of the recordset element.
If you post back the answer we can have a think about the result.
Alter today I will be at a site with an AD server so I will be able to run the code myself.
ASKER
var type = 8204
The variable type indicates a variant array which is fairly rare to find in a recordset. It could perhaps indicate a byte array perhaps.
I will take a look later when I am at a site with AD server.
I will take a look later when I am at a site with AD server.
I suppose we could see what is in the array:
MsgBox "ArraySize=" + Cstr(Ubound(objRecordSet.F ields("Ser ialNumber" ).Value))
and then
MsgBox "Element 0 VarType=" + Cstr(VarType(objRecordSet. Fields("Se rialNumber ").Value(0 )))
MsgBox "ArraySize=" + Cstr(Ubound(objRecordSet.F
and then
MsgBox "Element 0 VarType=" + Cstr(VarType(objRecordSet.
ASKER
MsgBox "ArraySize=" + Cstr(Ubound(objRecordSet.F ields("Ser ialNumber" ).Value))
got this:
arraysize=0
MsgBox "Element 0 VarType=" + Cstr(VarType(objRecordSet. Fields("Se rialNumber ").Value(0 )))
got this : error 450
got this:
arraysize=0
MsgBox "Element 0 VarType=" + Cstr(VarType(objRecordSet.
got this : error 450
ASKER
wow, there is some good now, i can see in the local window when i step the code until i reach the line :
YoezCodeNumber = objRecordSet.Fields("Seria lNumber ").Value
it give me in local window:
YoezCodeNumber(0) and value = "123456789"
when i step after to the line :
msgbox YoezCodeNumber
it gives me the error "type mismatch"-13
how comes?? when the dim YoezCodeNumber as variant ????
YoezCodeNumber = objRecordSet.Fields("Seria
it give me in local window:
YoezCodeNumber(0) and value = "123456789"
when i step after to the line :
msgbox YoezCodeNumber
it gives me the error "type mismatch"-13
how comes?? when the dim YoezCodeNumber as variant ????
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
perfecto!!!
vadimrapp1, thnx u ALOT for helping me out solving this problem :} here.
vadimrapp1, me u plz guide me to link/stuff that can help me out as bigenner in advaced debugging topics and the arrays issues.
i`ll be very glad.
u got my 500 points:}
vadimrapp1, thnx u ALOT for helping me out solving this problem :} here.
vadimrapp1, me u plz guide me to link/stuff that can help me out as bigenner in advaced debugging topics and the arrays issues.
i`ll be very glad.
u got my 500 points:}
> advanced debugging topics
There's not much more; the only remaining thing related to debugging is what's called a "watch", under menu "debug". You specify the variable of interest, and then the code will break whenever the variable's value is changed.
Array issues - if you want to move in that direction, look at Visual Studio.Net, it's fully object-oriented, and there are tons of stuff to learn.
There's not much more; the only remaining thing related to debugging is what's called a "watch", under menu "debug". You specify the variable of interest, and then the code will break whenever the variable's value is changed.
Array issues - if you want to move in that direction, look at Visual Studio.Net, it's fully object-oriented, and there are tons of stuff to learn.
...also, grab a book in your local library about the tool you are using. Many developers are self-learners, learning as they go and encounter problems, and it's really eye-opening experience when at some point you open a book and suddenly realize how many things were just around the corner, while you were wasting time on useless struggles and investigations for years.
ASKER
thnx alot for ur advice:}
I would also caution you against dropping code here and instructing the VOLUNTEER Experts to "fix this". We're glad to help, but we're not your code monkeys.