Access 2010 ADO on Windows XP Mode (in ADDE format) - ms-access

I have a problem with ADO in My application. I have Access installed on my computer with Win7Pro and there I can use both version (ACCDB and ACCDE). But only ACCDB works under runtime (with SP1) in WinXPMode environment.
There is the code
Dim strSQL As String, Cnxn As ADODB.Connection, Rsxn As ADODB.Recordset
Dim lngDummy As Long
lngCount = DCount("[Sklad]", "cisSklad", "[Zobrazit]")
CountData = lngCount
If CountData = 0 Then Exit Sub
ReDim ItemValues(lngCount - 1)
Set Cnxn = CurrentProject.AccessConnection
Set Rsxn = New ADODB.Recordset
...
In ACCDE (under RunTime on XPMode):
The line Set Cnxn = CurrentProject.AccessConnection return the message Error 13: Type mismatch.
I have the reference to ADO 2.8.
Debug.Print CurrentProject.AccessConnection: Provider=Microsoft.Access.OLEDB.10.0;Persist Security Info=False;Data Source=C:\Work\SkladII\Sklad.accde;User=Admin;Data Provider=Microsoft.ACE.OLEDB.12.0
All tables in sklad.accde are linked
Do you have any idea, where is the problem?

Investigate whether this issue is confined to early binding for ADO in WinXPMode. Remove the reference for ADO and revise your code to use late binding.
Dim strSQL As String, Cnxn As Object, Rsxn As Object
Set Cnxn = CurrentProject.Connection
'Set Rsxn = New ADODB.Recordset
Set Rsxn = CreateObject("ADODB.Recordset")

Related

Run Time Error "424" Object Required / Ms Access VBA ./ Objects are declared but still the error Could some one spot the error?

Private Sub method3_Click()
Dim conn1 As ADODB.Connection
Dim recSet As ADODB.Recordset
mySQL = "Select * from Contact"
Set conn1 = New ADODB.Connection
conn1.Provider = "Microsoft.ACE.OLEDB.12.0"
'ERROR WHEN PROGRAM REACHES THE LINE BELOW
conn1.Open (Server.Mappath("G:\Data\StudentDB.accDB"))
Set recSet = New ADODB.Recordset
recSet.Open mySQL, conn1, adOpenDynamic, adLockOptimistic
mobile = recSet.Field(3)
recSet.Close
conn1.Close
Set conn = Nothing
Set recSet = Nothing
End Sub
Server is not defined at that exact line.
You can use SET Conn1 = CurrentProject.Connection to avoid having to create a new connection from scratch.

Error setting VBA Recordset of form from ADODB.recordset

I've created a function using VBA in MS Access 2010 to execute SQL server stored procedure and return value in ADODB.Recordset Object. However, I'm not able to set the MS Access form RecordSource or Recordset with the recordset that was return from ADODB connection.
Below's you'll find the code excerpt:
Dim objRs As ADODB.Recordset
Set objRs = call_proc("mySQLProc", "param")
Set Forms("form1").Recordset = objRs
Function header of call_proc:
Public Function call_proc(procName As String, procVal As String) As ADODB.Recordset
If I iterate through the objRS and do a Debug.Print I am able to see all the records. So I know the data is there. Just don't know how to fix the error of binding the data to the form.
The line of code below returns error:
Set Forms("form1").Recordset = objRs
Any suggesting kindly accepted.
Thank you in advance.
Fixed it. The issue was in my call_proc function. When I opened the ADODB.Recordset I didn't set the cursor location. See code below where I added "' <---#####ADD THIS"
Public Function call_proc(procName As String, procVal As String) As ADODB.Recordset
' Initialize variables.
Dim cn As New ADODB.Connection
Dim objCmd As New ADODB.Command
Dim objParm1 As New ADODB.Parameter
Dim objRs As New ADODB.Recordset
Dim ServerName As String, DatabaseName As String
ServerName = "YourServerName"
DatabaseName = "YourDatabaseName"
' Specify the OLE DB provider.
cn.Provider = "sqloledb"
' Set SQLOLEDB connection properties.
cn.Properties("Data Source").Value = ServerName
cn.Properties("Initial Catalog").Value = DatabaseName
cn.CursorLocation = adUseClient ' <---#####ADD THIS
' Windows authentication.
cn.Properties("Integrated Security").Value = "SSPI"
' Set CommandText equal to the stored procedure name.
objCmd.CommandText = procName
objCmd.CommandType = adCmdStoredProc
' Open the database.
cn.Open
objCmd.ActiveConnection = cn
' Automatically fill in parameter info from stored procedure.
objCmd.Parameters.Refresh
' Set the param value.
objCmd(1) = procVal
Set call_proc = objCmd.Execute
End Function

how to fill a recordset in vba in a module behind a db

I have tried many ways to get the job done. I am inexperienced with the
Access VBA.
I think the problem is how to set the current database. The code is in a module from another db as the current db. I have paste the code here in a module behind the
currentdb that also gives the same error. I have looked after very much questions.
It must be simple. But I don't see the answer.
Private Sub project()
Dim projectnamen As DAO.Database
Dim strSQL As String
Dim rs As DAO.Recordset
Dim strdbName As String
Dim strMyPath As String
Dim strdb As String
Dim accapp As Object
Path = "c:\GedeeldeMappen\programma en bestanden stiko"
strdbName="projektnamen.accdb"
strMyPath = Path
strdb = strMyPath & "\" & strdbName
'make the db "projectnamen"current. Perhaps this is possible with set??
Set accapp = CreateObject("Access.Application")
accapp.OpenCurrentDatabase (strdb)
'fieldname is naam_van_het_project
'tablename is projectnaam
strSQL = "SELECT All naam_van_het_project FROM projectnaam;"
'here i get an error "can't find the object Select All naam_van_het_project
'FROM projectnaam" error 3011
Set rs = CurrentDb.OpenRecordset(strSQL, dbOpenTable)
rs.MoveFirst
Do While Not rs.EOF
MsgBox (rs)
rs.MoveNext
Loop
End Sub
I think you want to run that query against the db which you opened in the new Access session, accapp.
The CurrentDb method is a member of Application. So qualify CurrentDb with the object variable name of that other application session.
'Set rs = CurrentDb.OpenRecordset(strSQL, dbOpenTable)
Set rs = accapp.CurrentDb.OpenRecordset(strSQL, dbOpenSnapshot)
Note OpenRecordset won't let you use dbOpenTable with a query. So I arbitrarily chose dbOpenSnapshot instead. If that's not what you want, substitute a different constant from the RecordsetTypeEnum Enumeration (see Access help topic for details).

VBA conversion Office 2007 to Office 2010

I have a function in an Access 2007 database, which has been working fine until my PC was upgraded to Office 2010. The procedure is below and the offending line is that where 'originalFolder' is set:
Function ExportToSharePoint()
Dim oFs As New FileSystemObject
Dim originalFolder As Folder
Dim destinationPath As String
Dim ofile As file
Dim XLApp As Excel.Application
Dim xlwb As Excel.Workbook
Dim strFileName As String
Dim oFolder As String
oFolder = "//chs114file1/dovpasres/Public/Script/InfoCentre/Delays"
Set oFs = CreateObject("Scripting.FileSystemObject")
Set XLApp = New Excel.Application
Kill "K:\Public\Script\InfoCentre\Delays\*.xlk"
Set originalFolder = oFs.GetFolder(oFolder)
destinationPath = "https://companyname.sharepoint.com/PRR/Documents/"
For Each ofile In originalFolder.Files
strFileName = oFs.GetFileName(ofile)
Set xlwb = XLApp.Workbooks.Open(ofile)
xlwb.SaveAs (destinationPath + strFileName)
Next
xlwb.Close True
XLApp.Quit
Set xlwb = Nothing
Set XLApp = Nothing
End Function
The error I'm getting is:
Error 13: data type mismatch
I'm mystified as this is a string, as required?
The Microsoft documentation lists the GetFolder return type as being Folder, but I suspect your problem is being caused by mixing late binding (via CreateObject) with early binding (via the strongly-typed Folder variable).
Either import the reference to avoid the CreateObject call, or change the type to a variant, or perhaps object:
Dim originalFolder As variant

MySQL Sample for Visual Basic 6.0 - read/write

I'd like to find a simple example of working with remote MySQL base. I know, there are some tutorial over the internet, explaining how to set up ADODB.Connection and connectionstrings, but I couldnt make it work. Thanks for any help!
Download the ODBC connector from the MySQL download page.
Look for the right connectionstring over here.
In your VB6 project select the reference to Microsoft ActiveX Data Objects 2.8 Library. It's possible that you have a 6.0 library too if you have Windows Vista or Windows 7. If you want your program to run on Windows XP clients too than your better off with the 2.8 library. If you have Windows 7 with SP 1 than your program will never run on any other system with lower specs due to a compatibility bug in SP1. You can read more about this bug in KB2517589.
This code should give you enough information to get started with the ODBC connector.
Private Sub RunQuery()
Dim DBCon As adodb.connection
Dim Cmd As adodb.Command
Dim Rs As adodb.recordset
Dim strName As String
'Create a connection to the database
Set DBCon = New adodb.connection
DBCon.CursorLocation = adUseClient
'This is a connectionstring to a local MySQL server
DBCon.Open "Driver={MySQL ODBC 5.1 Driver};Server=localhost;Database=myDataBase; User=myUsername;Password=myPassword;Option=3;"
'Create a new command that will execute the query
Set Cmd = New adodb.Command
Cmd.ActiveConnection = DBCon
Cmd.CommandType = adCmdText
'This is your actual MySQL query
Cmd.CommandText = "SELECT Name from Customer WHERE ID = 1"
'Executes the query-command and puts the result into Rs (recordset)
Set Rs = Cmd.Execute
'Loop through the results of your recordset until there are no more records
Do While Not Rs.eof
'Put the value of field 'Name' into string variable 'Name'
strName = Rs("Name")
'Move to the next record in your resultset
Rs.MoveNext
Loop
'Close your database connection
DBCon.Close
'Delete all references
Set Rs = Nothing
Set Cmd = Nothing
Set DBCon = Nothing
End Sub