How to get a persons active directory groups? - vb.net

I am using this asmx.VB code to authenticate a user in AD. I need to also bring back what groups they are members of. Any help would be appreciated.
<WebMethod(Description:="Checks User against Active Directory.", EnableSession:=False)> _
Public Function CHECK_AD(ByVal userid As String, ByVal Password As String) As Integer
Dim iErrorNumber As Integer
Dim isPass As Boolean = False
Try
Dim pc As New PrincipalContext(ContextType.Domain, "SomeDomain")
isPass = pc.ValidateCredentials(userid, Password, ContextOptions.Negotiate)
If isPass = True Then
iErrorNumber = 1
Else
iErrorNumber = 0
End If
Catch ex As Exception
iErrorNumber = -1
End Try
Return iErrorNumber
End Function

I Have this code to get properties of user in active directory, maybe can help you, just add a button and if you want uncomment the first three comment lines and comment the first three lines of code after declarations.
(sorry the code is in spanish).
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim objetoUsuario, gruposSeguridad
Dim ultimoInicioSesion As String
Dim dominio As String
Dim nombreUsuario As String
Dim estadoCuenta As String
Dim gruposSeguridadUsuario As String = ""
'dominio = InputBox("Nombre del dominio Windows Server", "")
dominio = Environment.UserDomainName
'nombreUsuario = InputBox("Nombre de usuario del dominio", "")
nombreUsuario = Environment.UserName
' On Error GoTo cError
On Error Resume Next
objetoUsuario = GetObject("WinNT://" + dominio + "/" + nombreUsuario + ",user")
If Err.Number = 0 Then
If objetoUsuario.AccountDisabled = True Then
estadoCuenta = "Deshabilitado"
ultimoInicioSesion = "No existe"
Else
estadoCuenta = "Habilitado"
ultimoInicioSesion = objetoUsuario.Get("Lastlogin")
End If
gruposSeguridad = ""
For Each gruposSeguridad In objetoUsuario.Groups
If gruposSeguridadUsuario = "" Then
gruposSeguridadUsuario = gruposSeguridad.Name
Else
gruposSeguridadUsuario = gruposSeguridadUsuario + ", " + gruposSeguridad.Name
End If
Next
'Mostramos los datos del usuario
MsgBox("Nombre completo: " & objetoUsuario.Get("Fullname") & vbCrLf & _
"Descripción: " & objetoUsuario.Get("Description") & vbCrLf & _
"Nombre: " & objetoUsuario.Get("Name") & vbCrLf & _
"Carpeta de inicio: " & objetoUsuario.Get("HomeDirectory") & vbCrLf & _
"Script de inicio: " & objetoUsuario.Get("LoginScript") & vbCrLf & _
"Último inicio de sesión: " & ultimoInicioSesion & vbCrLf & _
"Perfil: " & objetoUsuario.Get("Profile") & vbCrLf & _
"Estado de la cuenta: " & estadoCuenta & vbCrLf & _
"Grupos seguridad: " & gruposSeguridadUsuario, vbInformation + vbOKOnly)
objetoUsuario = Nothing
Else
MsgBox("No existe el usuario " + nombreUsuario + " o el dominio " + dominio, vbExclamation + vbOKOnly)
End If
'cSalir:
' Exit Sub
'
'cError:
' MsgBox "Error " + CStr(Err.Number) + " " + Err.Description
' GoTo cSalir
End Sub

Related

Is it possible to identify through OUTLOOK triggers/events to which shared mail box has received a new email?

We are trying to store new mail item components into excel and assign tkt id, have tried doing it with single shared mailbox and succeeded but we want to implement same for 20 shared mail boxes. how can outlook vba event/trigger identify as soon as new email arrives to one of the 20 shared mail boxes.
this is code which will only work for default inbox:
Private Sub inboxItems_ItemAdd(ByVal Item As Object)
Dim Msg As Outlook.MailItem
Dim MessageInfo
Dim Result
If TypeName(Item) = "MailItem" Then
Dim cn As Object
Dim sCon As String
Dim sSQL As String
Dim bytHasAttachment As String
Dim strAddress As String
Dim objSender, exUser
Dim olRecipient As Outlook.Recipient
Dim strToEmails, strCcEmails, strBCcEmails As String
For Each olRecipient In Item.Recipients
Dim mail As String
If olRecipient.AddressEntry Is Nothing Then
mail = olRecipient.Address
ElseIf olRecipient.AddressEntry.GetExchangeUser Is Nothing Then
mail = olRecipient.Address
Else
mail = olRecipient.AddressEntry.GetExchangeUser.PrimarySmtpAddress
End If
If olRecipient.Type = Outlook.OlMailRecipientType.olTo Then
strToEmails = strToEmails + mail & ";"
ElseIf olRecipient.Type = Outlook.OlMailRecipientType.olCC Then
strCcEmails = strCcEmails + mail & ";"
ElseIf olRecipient.Type = Outlook.OlMailRecipientType.olBCC Then
strBCcEmails = strBCcEmails + mail & ";"
End If
Next
With Item
If Item.Attachments.Count > 0 Then
bytHasAttachment = 1
Else
bytHasAttachment = 0
End If
End With
'On Error Resume Next 'PropertyAccessor can raise an exception if a property is not found
If Item.SenderEmailType = "SMTP" Then
strAddress = Item.SenderEmailAddress
Else
'read PidTagSenderSmtpAddress
strAddress = Item.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x5D01001F")
If Len(strAddress) = 0 Then
Set objSender = Item.Sender
If Not (objSender Is Nothing) Then
'read PR_SMTP_ADDRESS_W
strAddress = objSender.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x39FE001F")
If Len(strAddress) = 0 Then
Set exUser = objSender.GetExchangeUser
If Not (exUser Is Nothing) Then
strAddress = exUser.PrimarySmtpAddress
End If
End If
End If
End If
End If
On Error GoTo ErrorHandler
Set cn = CreateObject("ADODB.Connection")
sCon = "Driver=MySQL ODBC 8.0 ANSI Driver;SERVER=localhost;UID=root;PWD={Platinum#123};DATABASE=liva_dev_gm;PORT=3306;COLUMN_SIZE_S32=1;DFLT_BIGINT_BIND_STR=1"
cn.Open sCon
sSQL = "INSERT INTO tbl_gmna_emailmaster_inbox (eMail_Icon, eMail_MessageID, eMail_Folder, eMail_Act_Subject, eMail_From, eMail_TO, eMail_CC, " & _
"eMail_BCC, eMail_Body, eMail_DateReceived, eMail_TimeReceived, eMail_Anti_Post_Meridiem, eMail_Importance, eMail_HasAttachment) " & _
"VALUES (""" & Item.MessageClass & """, " & _
"""" & Item.EntryID & """, " & _
"""Inbox""" & ", " & _
"""" & Item.Subject & """, " & _
"""" & strAddress & """, " & _
"""" & strToEmails & """, " & _
"""" & strCcEmails & """, " & _
"""" & strBCcEmails & """, " & _
"""" & Item.Body & """, " & "'" & Format(Item.ReceivedTime, "YYYY-MM-DD") & "', " & "'" & Format(Item.ReceivedTime, "hh:mm:ss") & "', " & "'" & Format(Item.ReceivedTime, "am/pm") & "', " & "'" & Item.Importance & "', " & "'" & bytHasAttachment & "')"
cn.Execute sSQL
End If
ExitNewItem:
bytHasAttachment = ""
Exit Sub
ErrorHandler:
MsgBox Err.Number & " - " & Err.Description
Resume ExitNewItem
End Sub
If the 20 shared mailboxes are in the navigation pane.
Option Explicit
Private WithEvents inboxItms As Items
Private WithEvents sharedInboxItms1 As Items
' ...
Private WithEvents sharedInboxItms20 As Items
Private Sub Application_Startup()
Dim defaultInbox As Folder
Dim sharedMailbox1 As Folder
Dim sharedInbox1 As Folder
' ...
Dim sharedMailbox20 As Folder
Dim sharedInbox20 As Folder
Set defaultInbox = Session.GetDefaultFolder(olFolderInbox)
Set inboxItms = defaultInbox.Items
Set sharedMailbox1 = Session.Folders("SharedMailbox1#somewhere.com")
Set sharedInbox1 = sharedMailbox1.Folders("Inbox")
' typo fixed
'Set sharedInboxItms1 = sharedInbox1.Folders("Inbox").Items
Set sharedInboxItms1 = sharedInbox1.Items
' ...
Set sharedMailbox20 = Session.Folders("SharedMailbox20#somewhere.com")
Set sharedInbox20 = sharedMailbox20.Folders("Inbox")
' typo fixed
'Set sharedInboxItms20 = sharedInbox20.Folders("Inbox").Items
Set sharedInboxItms20 = sharedInbox20.Items
End Sub
Private Sub inboxItms_ItemAdd(ByVal Item As Object)
' current code for default inbox
End Sub
Private Sub sharedInboxItms1_ItemAdd(ByVal Item As Object)
inboxItms_ItemAdd Item
End Sub
' ...
Private Sub sharedInboxItms20_ItemAdd(ByVal Item As Object)
inboxItms_ItemAdd Item
End Sub

VBA/Access: How to stop "You... FORM to be active window"

I want to be able to tell IF a form is the active window.
It seems simply invoking that method produces an error. I guess I could catch that error and run with it, but it's a backwards way of doing it.
Screen.ActiveForm.Name
This needs a form to be active. If I am breaking any rules of stackOverflow please be kind and remind me as I am new to forum.
Screen.parent, screen.activeControl, etc. What if VBA editor is open, as often it is?
Function CStatus(strStatus, ByRef intType As Integer, Optional ByRef erNo, Optional erMsg, Optional strDatum)
'pXname = "CStatus"
'pXStack = Left(pXStack, 500) & ">" & pXname
'Updates and manages the status bar
Dim strPreamble As String, strOut As String, strForm As String, strComment As String, strSQL As String, strPxStack As String, strCErrStack As String
Dim intColor As Double
Dim intPreLen As Integer
'On Error GoTo err_hand
'Color Codes
'12632256 = Lt Grey
'33023 = Orange
'65280 = Green
'16744576 = Steel Grey
'Define "Constants"
intPreLen = 350 'Length of previous message cache
'** Fix missings
If (IsMissing(strDatum) = True) Then strDatum = "[N/A]"
'** Other inits
strWindow = Screen.Parent.Name
strForm = Screen.ActiveForm.Name
'** intDebug ' Minimum Level of to report to status
'bEcho = True 'Whether to echo to status
intColor = errNoColor(intType)
'Error-level idiot explanations
strComment = "0"
If IsMissing(erNo) Then erNo = 0
If (IsNull(erMsg) = False) Then
If IsMissing(erMsg) = False Then strComment = erMsg
End If
strComment = errorTree(erNo)
strPreamble = Left(strPreamble, intPreLen) & "..."
strErrStack = Left(strErrStack, intPreLen) & " > " & pXname & ":" & intType
strCErrStack = strErrStack
reS:
If ((strForm = "finvmain") Or (strForm = "fclips")) Then Screen.ActiveForm.timeStatusUpdated = Now() 'Small field keeps time
If bEcho = True Then
strPxStack = ""
strCErrStack = "" 'Internal error stack
End If
strOut = Now() & " " & intType & " (" & strType & "): " & erNo & " " & strCErrStack & " >> " & strComment & " / " & strStatus & " [" & strDatum & "] .. " & strPreamble
If bEcho = True Then
If (strForm = "fInvMain") Then Screen.ActiveForm.txtStatus2 = Screen.ActiveForm.txtStatus 'Added second window to show previous message
Screen.ActiveForm.txtStatus = strOut
End If
Screen.ActiveForm.txtStatus.ForeColor = intColor
If strForm = "fInvMain" Then strTag = Screen.ActiveForm.Controls("txttag").value
'***Event Log
If erNo = "" Then erNo = 0
If IsMissing(erMsg) = True Then erMsg = ""
If IsMissing(strDatum) = True Then strDatum = ""
If Len(strPreamble) < 2 Then strPreamble = "[None]"
'Fixxed - Syntax Error for Some Odd Reason! Apr 27th
If ((strTag = Empty) And (strForm = "fInvMain")) Then strTag = Screen.ActiveForm.txtTag 'Attempt to add tag# to entry
strStatus = cleanString(strStatus)
strDatum = cleanString(strDatum)
strComment = cleanString(strComment)
strSQL = "INSERT INTO tEvents(txtdate, myerrno, interrno, myerrmsg, interrmsg, txtform, stack, process, Datum, idLink) VALUES ('" & Now() & "','" & intType & "','" & erNo & "','" & strStatus & "','" & strComment & "','" & strForm & "','" & strErrStack & "','" & pXname & "','" & strDatum & "','" & strTag & "');"
CurrentDb.Execute strSQL, dbFailOnError
Exit Function
err_hand:
If Err.Number = 2475 Then
bEcho = False
Resume reS
Else: MsgBox "555: CStatus Internal Error, Turn off error handling to view"
End If
End Function
I need a boolean true or false IF form is active. If it isn't, I can't put stuff into a textbox in that.
To determine if a particular form is open then set focus to form:
If CurrentProject.AllForms("finvmain").IsLoaded
strForm = "finvmain"
Elseif CurrentProject.AllForms("fclips").IsLoaded Then
strForm = "fclips"
End If
If strForm <> "" Then DoCmd.SelectObject acForm, strForm

VBA Macro TO Export Splines from catia to text file(.dat)

so I was wondering if i could get some help here. so basically i am trying to find out how to write a dat file that will be able to import splines into Catia. These splines when imported are supposed to act like meshes on a structure, that is, picture a meshed structure, but instead of mesh it will be splines on it. so right now i thought to learn a macro that exports a few splines i created on a structure into a text(.dat) file. but i have been having troubles with the macro i have as it asks me to select a spline, but wont allow me to click on the spline in spec tree. The thing is that i have lots of splines and i would like the macro to just select splines automatically without asking and export them..... PLS HELP ME. thanks alot.
So here is the code:
Sub CATMain()
'*** *** Definition Variables
Dim CtrlPoint()
Dim oCoordinates(1)
Dim StartKrit As Integer
'*** Query document type ***
StartKrit = 0
Set oDoc = CATIA.ActiveDocument
ObjType = TypeName(oDoc)
If ObjType = "PartDocument" Then
DocType = "Part"
StartKrit = 1
ElseIf ObjType = "DrawingDocument" Then
DocType = "Drawing "
StartKrit = 1
End If
If StartKrit = 0 Then
box = MsgBox(" The active document is neither a CATPart still CATDrawing! " + Chr(10) + _
" The macro can not continue and will now exit " + Chr(10) + _
"Please select a CATPart or a CATDrawing and start the macro again!", vbCritical + vbOKOnly, "incorrect document type")
Exit Sub
End If
'*** Create the * .txt files ***
StorePath = "C: \"
StoreName = "Splinekoordinaten" & Date
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.FileExists(StorePath & StoreName & ".txt ") = True Then
box = MsgBox(" file ==> " + StorePath + StoreName + " <== already exists! " + Chr(10) + " Do you want to overwrite the file? ", vbCritical + vbYesNo, "file already exists ")
If box = vbNo Then
box = MsgBox(" The macro is now finished ", vbInformation + vbOKOnly, " the user stops ")
Exit Sub
End If
End If
Set A = fs.CreateTextFile("D:\school\INTERNSHIP\Macro\Newest.txt ", True)
A.WriteLine (" points coordinates of a spline ")
A.WriteLine (" ")
If DocType = " Part " Then
A.WriteLine (" name of CATParts: " & oDoc.Name)
ElseIf DocType = " Drawing " Then
A.WriteLine ("name of CATDrawing:" & oDoc.Name)
End If
A.WriteLine ("")
'*** Readout from the CATDrawing ***
If DocType = "Drawing" Then
Dim otype2D(0)
Dim Selection
Set mysel = oDoc.Selection
mysel.Clear
otype2D(0) = "Spline2D"
mysel.Clear
box = MsgBox(" Please select now the spline ", vbInformation + vbOKCancel, " spline Select ")
If box = vbCancel Then
box = MsgBox(" you have the selection canceled " + Chr(10) + _
" the macro is now finished! ", vbCritical, "abort by user")
If fs.FileExists(StorePath & StoreName & ".txt") = True Then
A.Close
fs.DeleteFile (StorePath & StoreName & ".txt")
End If
Exit Sub
End If
Selection = mysel.SelectElement2(otype2D, "Please select the spline", False)
If Selection = "Normal" Then
oSplineName = mysel.Item(1).Value.Name
Set oSpline = mysel.Item(1).Value
A.WriteLine ("name of the selected spline:" & oSplineName)
A.WriteLine ("")
A.WriteLine ("")
Else
box = MsgBox("you have canceled the selection" + Chr(10) + _
"the macro is now finished! ", vbCritical, " abort by user ")
If fs.FileExists(StorePath & StoreName & " .txt ") = True Then
A.Close
fs.DeleteFile (StorePath & StoreName & " .txt ")
End If
Exit Sub
End If
mysel.Clear
Set QuCtrlP = oSpline.EndPoint
QuCtrlPRaw = QuCtrlP.Name
QuCtrlPSemi = Split(QuCtrlPRaw, ".")
QuCtrlPFin = QuCtrlPSemi(1) - 1
ReDim Preserve CtrlPoint(QuCtrlPFin)
For j = 0 To QuCtrlPFin
Set CtrlPoint(j) = oSpline.GetItem("Ktrl-point." & j + 1)
CtrlPoint(j).GetCoordinates oCoordinates
A.WriteLine ("point" & j + 1 & "X / Y")
A.WriteLine (oCoordinates(0))
A.WriteLine (oCoordinates(1))
A.WriteLine ("")
Next
'*** readout from the CATPart ***
ElseIf DocType = "Part" Then
Dim otype3D(0)
Set mysel = oDoc.Selection
mysel.Clear
otype3D(0) = "Spline2D"
mysel.Clear
box = MsgBox("Please select now the spline", vbInformation + vbOKCancel, "spline Select")
If box = vbCancel Then
box = MsgBox("you have canceled the selection" + Chr(10) + _
"The macro is now finished!", vbCritical, "abort by user")
If fs.FileExists(StorePath & StoreName & ".txt") = True Then
A.Close
fs.DeleteFile (StorePath & StoreName & ".txt ")
End If
Exit Sub
End If
Selection = mysel.SelectElement2(otype3D, " Please select the spline ", False)
If Selection = " Normal " Then
oSplineName = mysel.Item(1).Value.Name
Set oSpline = mysel.Item(1).Value
A.WriteLine ("name of the selected spline:" & oSplineName)
A.WriteLine ("")
A.WriteLine ("")
Else
box = MsgBox("you have canceled the selection" + Chr(10) + _
"The macro is now finished!", vbCritical, "abort by user")
If fs.FileExists(StorePath & StoreName & ".txt") = True Then
A.Close
fs.DeleteFile (StorePath & StoreName & " .txt ")
End If
Exit Sub
End If
mysel.Clear
Set QuCtrlP = oSpline.EndPoint
QuCtrlPRaw = QuCtrlP.Name
QuCtrlPSemi = Split(QuCtrlPRaw, " ")
QuCtrlPFin = QuCtrlPSemi(1) - 1
ReDim Preserve CtrlPoint(QuCtrlPFin)
For j = 0 To QuCtrlPFin
Set CtrlPoint(j) = oSpline.GetItem("Ktrl-point." & j + 1)
CtrlPoint(j).GetCoordinates oCoordinates
A.WriteLine ("point" & j + 1 & "X / Y")
A.WriteLine (oCoordinates(0))
A.WriteLine (oCoordinates(1))
A.WriteLine ("")
Next
End If
'**** Issue Storage Location ****
Ml = "The macro has completed successfully"
M2 = "The * .txt file is saved under the following path:"
M2_ZU_1 = "==>"
M2_ZU_2 = "<== "
M3 = " Are you in the path now oeffnen? "
Title = "memory data"
skin = vbInformation + vbYesNo
query = MsgBox(Ml + Chr(10) + Chr(10) + M2 + Chr(10) + Chr(10) + M2_ZU_1 + StorePath + StoreName + M2_ZU_2 + Chr(10) + Chr(10) + M3, skin, Title)
If query = vbYes Then
ExplorerPath = "C: \ WINDOWS \ explorer.exe"
Explorer = CATIA.SystemService.ExecuteProcessus(ExplorerPath & "" & StorePath)
End If
End Sub
Your selectelement2 filter is set for spline2D, are you selected sketch splines or 3d splines?
If you are working with 3d splines like it sounds, you want to use this code:
mysel.Clear
otype3D(0) = "HybridShapeSpline"
mysel.Clear
box = MsgBox("Please select now the spline", vbInformation + vbOKCancel, "spline Select")
If box = vbCancel Then
box = MsgBox("you have canceled the selection" + Chr(10) + _
"The macro is now finished!", vbCritical, "abort by user")
If fs.FileExists(StorePath & StoreName & ".txt") = True Then
A.Close
fs.DeleteFile (StorePath & StoreName & ".txt ")
End If
Exit Sub
End If
Selection = mysel.SelectElement2(otype3D, " Please select the spline ", False)
You'll find more help on www.coe.org, there is a significant group of CATIA automators there.

Scan image in vba with cannon scanner not work

I have a vba code that scan image from scanner , the code works and doesnt have any problem with type hp an brother scanner but when I used it with canon can not find the scanner and send message no wia device. How can solve this problem
Private Sub Command10_Click()
Const wiaFormatJPEG = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}"
On Error GoTo Handle_Err
Dim Dialog1 As New WIA.CommonDialog, DPI As Integer, PP As Integer, l As Integer
Dim Scanner As WIA.Device
Dim img As WIA.ImageFile
Dim intPages As Integer
Dim strFileJPG As String
Dim blnContScan As Boolean ' to activate the scanner to start scan
Dim ContScan As String 'msgbox to chk if more pages are to be scanned
Dim strFilePDF As String
Dim RptName As String
Dim strProcName As String
strProcName = "ScanDocs"
DoCmd.SetWarnings False
DoCmd.RunSQL "delete from scantemp"
DoCmd.SetWarnings False
blnContScan = True
intPages = 0
Do While blnContScan = True
DPI = 200
PP = 1 'No of pages
Set Scanner = Dialog1.ShowSelectDevice(WIA.WiaDeviceType.ScannerDeviceType, True, False)
Set img = Dialog1.ShowTransfer(Scanner.Items(1), wiaFormatJPEG, True)
strFileJPG = ""
intPages = intPages + 1
strFileJPG = "\\User-pc\saveimage\" & num & Trim(str(intPages)) & ".jpg"
img.SaveFile (strFileJPG)
DoCmd.RunSQL "insert into scantemp (picture) values ('" & strFileJPG & "')"
DoCmd.SetWarnings False
Set Scanner = Nothing
Set img = Nothing
' strFileJPG = ""
'Prompt user if there are additional pages to scan
ContScan = MsgBox("?save another page ", vbQuestion + vbYesNoCancel)
If ContScan = vbNo Then
blnContScan = False
ElseIf ContScan = vbCancel Then
DoCmd.RunSQL "delete from scantemp where picture = '" & strFileJPG & "'"
End If
'''''''''''''''
Loop
Dim Image_Path As String
GoTo StartPDFConversion
StartPDFConversion:
Dim s As String
strFilePDF = "\\User-pc\saveimage\" & (num) & ".pdf"
RptName = "rptScan"
DoCmd.OpenReport RptName, acViewReport, , , acHidden
DoCmd.Close acReport, RptName, acSaveYes
DoCmd.OutputTo acOutputReport, RptName, acFormatPDF, strFilePDF
Me.imgp = strFilePDF
DoCmd.RunSQL "delete from scantemp" 'delete all data from table scantemp after converted it to pdf
'/*******************************\
'/********************************************\
Handle_Exit:
Exit Sub
Handle_Err:
Select Case Err.Number
Case 2501
Resume Handle_Exit
Case Else
MsgBox "the." & vbCrLf & vbCrLf & _
"In Function:" & vbTab & strProcName & vbCrLf & _
"Err Number: " & vbTab & Err.Number & vbCrLf & _
"Description: " & vbTab & Err.Description, 0, _
"Error in " & Chr$(34) & strProcName & Chr$(34)
Resume Handle_Exit
End Select
Exit Sub
End Sub
Option Compare Database
Private Declare Function TWAIN_AcquireToFilename Lib "TWAIN32d.DLL" (ByVal hwndApp As Long, ByVal bmpFileName As String) As Integer
Private Declare Function TWAIN_IsAvailable Lib "TWAIN32d.DLL" () As Long
Private Declare Function TWAIN_SelectImageSource Lib "TWAIN32d.DLL" (ByVal hwndApp As Long) As Long
Private Sub cmdScan_Click()
Dim Ret As Long, PictureFile As String
Dim intPages As Integer
Dim blnContScan As Boolean
Dim ContScan As String 'msgbox to chk if more pages are to be scanned
blnContScan = True
intPages = 0
Do While blnContScan = True
DPI = 200
PP = 1 'No of pages
intPages = intPages + 1
PictureFile = CurrentProject.Path & "\" & myfolder & "\" & Me.number & Trim(Str(intPages)) & ".jpg"
Ret = TWAIN_AcquireToFilename(Me.hwnd, PictureFile)
ContScan = MsgBox("? ÍÝÙ ÕæÑÉ ÇÎÑì ", vbQuestion + vbYesNo, "ÊäÈíÉ")
If ContScan = vbNo Then
blnContScan = False
End If
Loop

How to add Levels to TreeView

Hey I am trying to add a Second level to a tree view the First level being GroupName and the Second level being Description
I have this code but is just creating separate nodes for each instead oh being under different Groups names
Sub LoadGroupTree()
'**Loads Property List
' Initialise Error Checking
' Dimension Local Variables
Dim uRecSnap As ADODB.Recordset
Dim uPar As ADODB.Parameter
Dim uNode As TreeNode
' Dim iGroupID As Integer = 0
Dim uStackframe As New Diagnostics.StackFrame
Try
' Check For Open Connection
If uDBase Is Nothing Then
OpenConnection()
bConnection = True
End If
' Run Stored Procedure - Load Property List (Based on Search Value)
uCommand = New ADODB.Command
With uCommand
.ActiveConnection = uDBase
.CommandType = ADODB.CommandTypeEnum.adCmdStoredProc
.CommandTimeout = 0
uPar = .CreateParameter("#SearchValue", ADODB.DataTypeEnum.adVarChar, ADODB.ParameterDirectionEnum.adParamInput, 30)
.Parameters.Append(uPar)
.Parameters("#SearchValue").Value = txtFilter.Text
.CommandText = "InspsectionGroup_LoadRecords"
uRecSnap = .Execute
End With
' Suppress TreeView Repaint / Clear TreeView
tvwInspectionGroups.BeginUpdate()
tvwInspectionGroups.Nodes.Clear()
tvwInspectionGroups.ShowNodeToolTips = True
' Populate List
Do Until uRecSnap.EOF
uNode = tvwInspectionGroups.Nodes.Add("P" & Format(uRecSnap("InspectionGroupID").Value, "0000"), uRecSnap("GroupName").Value)
uNode.Tag = "P:" & Format(uRecSnap("InspectionGroupID").Value, "0000") & ":01:"
uNode.Nodes.Add("D" & Format(uRecSnap("GroupName").Value, "0000"), uRecSnap("Description").Value)
uNode.Tag = "D:" & Format(uRecSnap("GroupName").Value, "0000") & ":02:"
uNode.Nodes.Add("A" & Format(uRecSnap("Description").Value, "0000"), uRecSnap("AddressLine1").Value)
uNode.Tag = "A:" & Format(uRecSnap("Description").Value, "0000") & ":03:"
uRecSnap.MoveNext()
Loop
uRecSnap.Close()
' Repaint TreeView.
tvwInspectionGroups.EndUpdate()
tvwInspectionGroups.Refresh()
' Close Connection
Catch ex As Exception
' Catch Error
If Err.Number <> 0 Then
WriteAuditLogRecord(uStackframe.GetMethod.DeclaringType.FullName, uStackframe.GetMethod.Name.ToString, "Error", Err.Description & vbCrLf & vbCrLf & ex.StackTrace, 0)
MsgBox("System Error Ref: " & sAuditID & vbCrLf & uStackframe.GetMethod.DeclaringType.FullName & " / " & uStackframe.GetMethod.Name.ToString & vbCrLf & Err.Description & vbCrLf & vbCrLf & ex.StackTrace & Chr(13) & sErrDescription, MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, "Business Management System - Unexepected Error Ref: " & sAuditID)
End If
Finally
If bConnection Then CloseConnection()
uRecSnap = Nothing
End Try
Sub LoadGroupTree()
'**Loads Property List
' Initialise Error Checking
' Dimension Local Variables
Dim uRecSnap As ADODB.Recordset
Dim uPar As ADODB.Parameter
Dim uNode As TreeNode
Dim uNode3 As TreeNode
' Dim iGroupID As Integer = 0
Dim uStackframe As New Diagnostics.StackFrame
Try
' Check For Open Connection
If uDBase Is Nothing Then
OpenConnection()
bConnection = True
End If
' Run Stored Procedure - Load Property List (Based on Search Value)
uCommand = New ADODB.Command
With uCommand
.ActiveConnection = uDBase
.CommandType = ADODB.CommandTypeEnum.adCmdStoredProc
.CommandTimeout = 0
uPar = .CreateParameter("#SearchValue", ADODB.DataTypeEnum.adVarChar, ADODB.ParameterDirectionEnum.adParamInput, 30)
.Parameters.Append(uPar)
.Parameters("#SearchValue").Value = txtFilter.Text
.CommandText = "InspsectionGroup_LoadRecords"
uRecSnap = .Execute
End With
' Suppress TreeView Repaint / Clear TreeView
tvwInspectionGroups.BeginUpdate()
tvwInspectionGroups.Nodes.Clear()
tvwInspectionGroups.ShowNodeToolTips = True
' Populate List
Do Until uRecSnap.EOF
uNode = tvwInspectionGroups.Nodes.Add("P" & Format(uRecSnap("InspectionGroupID").Value, "0000"), uRecSnap("GroupName").Value)
uNode.Tag = "P:" & Format(uRecSnap("InspectionGroupID").Value, "0000") & ":01:"
uNode3 = uNode.Nodes.Add("D" & Format(uRecSnap("GroupName").Value, "0000"), uRecSnap("Description").Value)
uNode.Tag = "D:" & Format(uRecSnap("GroupName").Value, "0000") & ":02:"
uNode3.Nodes.Add("A" & Format(uRecSnap("Description").Value, "0000"), uRecSnap("AddressLine1").Value)
uNode3.Tag = "A:" & Format(uRecSnap("Description").Value, "0000") & ":03:"
uRecSnap.MoveNext()
Loop
uRecSnap.Close()
' Repaint TreeView.
tvwInspectionGroups.EndUpdate()
tvwInspectionGroups.Refresh()
' Close Connection
Catch ex As Exception
' Catch Error
If Err.Number <> 0 Then
WriteAuditLogRecord(uStackframe.GetMethod.DeclaringType.FullName, uStackframe.GetMethod.Name.ToString, "Error", Err.Description & vbCrLf & vbCrLf & ex.StackTrace, 0)
MsgBox("System Error Ref: " & sAuditID & vbCrLf & uStackframe.GetMethod.DeclaringType.FullName & " / " & uStackframe.GetMethod.Name.ToString & vbCrLf & Err.Description & vbCrLf & vbCrLf & ex.StackTrace & Chr(13) & sErrDescription, MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, "Business Management System - Unexepected Error Ref: " & sAuditID)
End If
Finally
If bConnection Then CloseConnection()
uRecSnap = Nothing
End Try