I am calling a vb.net function of a dll from below VBA code in MDB.
I am calling Get_GDW_data_final sub from immediate Window.
Public Sub Get_GDW_data_final()
Dim r As New Get_GDW_Data.GDW
MsgBox r.DetailedWork()
End Sub
I have created Get_GDW_Data.dll added reference of it in MDB.
The coding of class is as below.
Public Class GDW
Public Function DetailedWork()
Dim lastrow As Long
Dim ADODBcnn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Access8\W156_RocketOffset_Backup.mdb;Persist Security Info=False;Mode=read")
Dim ADODBcmd As New OleDb.OleDbCommand
Dim ADODBcmd1 As New OleDb.OleDbCommand
Dim ADODBrst As OleDb.OleDbDataReader
ADODBcnn.Open()
ADODBcmd.CommandText = "select count(*) from input"
lastrow = ADODBcmd.ExecuteScalar()
ADODBcnn.Close()
Return lastrow.ToString()
End Function
End Class
Here I am getting error
Run-time Error -2147467259 (80004005)
The database has been put in a state by admin or machine 'Rachit' that prvents it from being opened or locked.
I discovered what the problem was:
It's a Limitation of Access that you can not access a table of a database using a dll from which you are calling the function :-)
INPUT is a reserved word, so try:
ADODBcmd.CommandText = "select count(*) from [input]"
Related
Here a sample code that produces the error. I have used MSscript in VB projects in the past and those projects are functioning.
The error reported is: "When casting from a number, the value must be a number less than infinity"
Or if anyone has another suggested way to easily add scripting to a project.
Private Sub Run_Script()
Dim scriptEngine As New MSScriptControl.ScriptControl()
Dim TestClass As New Sample
Dim ScriptCode As String
scriptEngine.Language = "VbScript"
scriptEngine.AddObject("Test", TestClass, True)
ScriptCode = "MsgBox ""tests"" "
scriptEngine.AddCode(ScriptCode)
End Sub
End Class
Public Class Sample
Public Sub Test()
MessageBox.Show("This is a test")
End Sub
End Class
I found the answer. I needed to set com visible to true. This is found under "Assembly Information"
I am trying to connect to HPQC though vbscript in excel. I have already added the OTA library to Reference.
When I am trying to instantiate an object as TDConnection,
Global tdc As TDConnection
Set tdc = new TDConnection
its throwing an error:
Run-time error '429':
ActiveX component can't create object.
I used the below code to check:
Sub Connect()
Dim tdc as TDConnection
Dim url as String
Dim Domain as String
Dim Project as String
Dim username as String
Dim Password as String
url = "http://qc.abcdef.com"
Domain = "NNNN"
Project = "NNNNNNN"
username = "ABCD"
Pasword = "XYZ"
Disconnect 'Disconnects any open connections
If (tdc Is Nothing) Then Set tdc = New TDConnection
If (tdc Is Nothing) Then GoTo ConnectionErr
tdc.InitConnectionEx url 'Initiate Connection
tdc.Login username, Password
tdc.Connect Domain, Project
MsgBox "Connection Established"
Exit Sub
ConnectionErr:
MsgBox "Connection Error"
End Sub
Then ran from cmd the below command
C:\Windows\SysWOW64> wscript.exe "C:\...\QC.vbs"
but facing error
Please help!
Try running your VB script with command prompt using specific cscript -
C:\WINDOWS\SysWOW64>cscript.exe ".... .vbs"
For more info refer https://community.hpe.com/t5/Quality-Center-ALM-Practitioners/ActiveX-component-can-t-create-object-TDApiOle80-TDConnection/td-p/4742677
I'm having trouble with a odbc connection in excel-vba tool.
Public connString As Connection
Sub login()
logout
Set wrkODBC1 = CreateWorkspace("NewODBC", "admin", "", dbUseODBC)
Set connString= wrkODBC1.OpenConnection("odbc-database", dbDriverNoPrompt, , "ODBC;uid=user;pwd=passwrd;DSN=odbc-database")
End Sub
Sub logout()
On Error Resume Next
connString.Close
wrkODBC1.Close
On Error GoTo 0
End Sub
When running this code:
login
txt = "SELECT [col1],[col1] FROM database.[dbo].[table]"
sqlToWorksheet sheet, connString, txt
Sub sqlToWorksheet(sheet, conn, sqlString)
Set temp = conn.OpenRecordset(sqlString, dbOpenSnapshot)
When conn.OpenRecordset is executed I get the error: Error 3420: Object invalid or no longer set. Anyone knows what wrong? Works with my other odbc connections. The database is a mssqlserver2012.
I forgot this instantiate wrkODBC1, working now.
Hey everyone. I'm fairly new to VB.NET and I'm looking to create a module that will contain all general SQL functionality like connect, disconnect and execute a sql query etc.
I think I'm almost there but the code keeps bombing in one place.
Can anyone see what is wrong with the following code?
It bombs here, setting the command object to a connection object. The opening and closing of the connection works fine.
cmdSystem.Connection = cnSystem
Or maybe I'm just thinking old VB and am going about this all wrong.
Public Module modGeneral
Private cnSystem As New SqlClient.SqlConnection
Private cmdSystem As SqlClient.SqlCommand
Public Sub ConnectToSQL()
Dim sConnectionString As String = "Data Source=SQL;Initial Catalog=XXXX;User ID=XXXX;Password=XXXX"
Try
cnSystem.ConnectionString = sConnectionString
cnSystem.Open()
Catch ex As Exception
End Try
End Sub
Public Sub DisconnectFromSQL()
Try
cnSystem.Close()
cnSystem.Dispose()
Catch ex As Exception
End Try
End Sub
Public Function lExecuteSQL(ByVal sSQL As String) As Long
Dim lRecordsAffected As Long = 0
Try
cmdSystem.Connection = cnSystem
cmdSystem.CommandText = sSQL
lRecordsAffected = cmdSystem.ExecuteNonQuery()
cmdSystem.Dispose()
Catch ex As Exception
End Try
Return lRecordsAffected
End Function
End Module
Thanks in advance.
at some point, you need to instantiate your command object like you did the connection.
have you considered having these functions in a class instead of a module?
Hi I am trying to create a VB.NET application which will (hopefully) reduce some time spent on some of my departments helpdesk calls. The part that I am stuck with is how to use VB.NET to remove a user from a group. The following is code that I have been playing with:
Public Shared Sub RemoveUserFromGroup(ByVal deUser As String, ByVal GroupName As String)
Dim entry As DirectoryEntry = ADEntry()
Dim mySearcher As DirectorySearcher = New DirectorySearcher(entry)
mySearcher.Filter = "(&(ObjectClass=Group)(CN=" & GroupName & "))"
mySearcher.PropertiesToLoad.Add("OrganizationalUnit")
mySearcher.PropertiesToLoad.Add("DistinguishedName")
mySearcher.PropertiesToLoad.Add("sAMAccountName")
Dim searchResults As SearchResultCollection = mySearcher.FindAll()
If searchResults.Count > 0 Then
Dim group As New DirectoryEntry(searchResults(0).Path)
Dim members As Object = group.Invoke("Members", Nothing)
For Each member As Object In CType(members, IEnumerable)
Dim x As DirectoryEntry = New DirectoryEntry(member)
MessageBox.Show(x.Properties("sAMAccountName").Value)
If x.Properties("sAMAccountName").Value = deUser Then
MessageBox.Show(searchResults.Item(0).Path.ToString)
MessageBox.Show(x.Properties("sAMAccountName").Value)
'group.Invoke("Remove", New Object() {x.Properties("OrganizationalUnit").Value})
group.Properties("member").Remove(x.Properties("OrganizationalUnit").Value)
End If
Next
End If
When I run the program, I recevie a COMException was unhandled, unspecified error at the group.properties line. When using group.invoke I receive the error TargetInvocationException was unhandled.
My aim is to pass as a string the username (sAMAccountName) and the groupname (sAMAccountName) to the function which will locate the user and remove them from the group.
I am new to VB.NET and would appreciate any assistance people can provide.
I am coding in .NET 2.0 as I am unsure if the server it will live on will have 3.5 installed.
Well the error message 0x80004005 E_FAIL Unspecified failure is not very helpful. I often get frustrated when working with Active Directory.
Try changing line:
group.Properties("member").Remove(x.Properties("OrganizationalUnit").Value)
to
group.Invoke("Remove", New Object() {x.Path.ToString()})
If you need more reference take a look at this article on VB.net Heaven by Erika Ehrli. The article covers various use cases with Active Directory.
I hope that helps.