Access 2003 via Citrix: 'Error Loading DLL' with CurrentProject.Connection - ms-access

Set up an Access Project to be opened via Citrix. However, there is some VBA code that prevents it from working:
Dim rs As ADODB.Recordset
Set rs = CurrentProject.Connection.Execute("Query")
The .Connection bit is highlighted. This works when it is not opened via Citrix though (i.e. just on users desktop).

Problem was due to the Citrix server not having the latest Jet Service Pack for Access.

I don't have a lot of experience with ADO but I'm thinking there's a references problem of some sort. Or that you are referencing a newer version of ADO on your system than is avaialble on the Citrix box. Run the following code and post back the results.
Sub ViewReferenceDetails()
Dim ref As Reference
For Each ref In Access.References
Debug.Print ref.Name & " - " & ref.Major & "." & ref.Minor & " - " & ref.FullPath
Next ref
End Sub
Also when you state Access project do you mean an ADP against SQL Server or an MDB/ACCDB against an Access data file?

Your code looks wrong to me. Should the rs Object not be a Recordset?
i.e.
Dim rs As ADODB.Recordset
'Instead of
Dim rs As ADODB.Connection
The code should not run at all - you should receive a Type Mismatch error.

Related

Failed VBA SQL Query in Outlook 365?

I have some VBA code in Outlook that runs a SQL query and populates a userform I designed. This code was previously running fine on one PC, then I was issued a new laptop and I copied the outlook VBA module directly over.
When I try to run, I just get an error "Compile Error: Can't find project or library" and the text "adOpenStatic" in the RS.open statement is highlighted. Previously, I had seen the same error if my SQL query was bad or the driver was missing, but I double checked both. I copied the EXACT code into an excel VBA module and it ran as expected.
The only other difference I can see is that I went from Outlook 2019 to Office 365 for Enterprise.
Dim server, database, login_user, password, port As String
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim strSQL As String
server = "dummy"
database = "dummy"
login_user = "dummy"
password = "dummy"
port = "dummy"
Set cn = New ADODB.Connection
cn.ConnectionString = "DRIVER={MySQL ODBC 8.0 ANSI Driver};Provider=MSDASQL;" & "SERVER=" & server & ";" & " DATABASE=" & database & ";" & "UID=" & login_user & ";PWD=" & password & "; OPTION=3; PORT=" & port & ";Connect Timeout=20;"
'open the connection
cn.Open
Set rs = New ADODB.Recordset
strSQL = "SELECT * FROM quote WHERE id = 1505"
rs.Open strSQL, cn, adOpenStatic
With rs
Do Until .EOF
'parse out relevant project information
rs.MoveNext
Loop
End With
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
I can run the exact query in MySQL workbench, and it works as expected. The fact that the identical code can run in Excel without issue tells me there is perhaps a syntax difference in Outlook that I am unaware of? Anyone else have ideas?
NOTE, if it wasn't already obvious, I am omitting my database details with "Dummy", but the real code has the correct strings.
This code was previously running fine on one PC, then I was issued a new laptop and I copied the outlook VBA module directly over.
You need to re-add all COM references you had on the old machine.
From the Tools menu, choose References to display the References dialog box.
The References dialog box shows all object libraries registered with the operating system. Scroll through the list for the application whose object library you want to reference. If the application isn't listed, you can use the Browse button to search for object libraries (*.olb and .tlb) or executable files (.exe and *.dll on Windows). References whose check boxes are selected are used by your project; those that aren't selected are not used, but can be added.
Go to the VBA Editor, and choose Tools-References; and tick the box next to 'Microsoft ActiveX Data Objects' (the latest version). It should compile ok now.

Syntax Error in VBA Code - Run Time error '-2147217900(80040e14)'

I have another issue now that we have decided to move things to a server since the database cannot handle the amount of data being captured.
The short of it is:
I have tried using my existing code via transferspreadsheet method to import data to a tmp file but this is taking to long now with the SQL Server. I would like to stay with doing this programmatically and have been working with the following code. I am not sure if this will work since I can't get past the syntax error. If anyone could help it would be greatly appreciated
code start:
Dim CN As ADODB.Connection
Dim strConn As String
Dim strSQL As String
Dim strXLSource As String
Dim lngRecsaff As Long
strConn = "Driver={SQL Server};Server=logistics.companyname.com;Database=ITM;Trusted_Connection=Yes;"
Set CN = New ADODB.Connection
CN.Open strConn
strXLSource = ("C:\Users\GONZW053\Documents\My Desktop Documents\Monster Database Exports\DTPM - WDW DLR\book1.xlsx;Extended Properties= Excel 12.0")
strSQL = "INSERT INTO [tmpWDWDLR] SELECT * FROM OPENDATASOURCE('Microsoft.ACE.OLEDB.12.0','Data Source = '" & strXLSource & "')"
Debug.Print strSQL
CN.Execute strSQL, lngRecsaff, adExecuteNoRecords
Debug.Print "Records Affected: " & lngRecsaff
CN.close
Set CN = Nothing
I look forward to the help as this site and contributors have been a great source of knowledge. Thanks!
Since the Excel file is not present on the server, you can't use it in OPENROWSET or OPENDATASOURCE commands.
Using Access, however, you can use an insert query to insert data from the Excel file into SQL server:
INSERT INTO [ODBC;Driver={SQL Server};Server=logistics.companyname.com;Database=ITM;Trusted_Connection=Yes;].tmpWDWDLR
SELECT *
FROM [Sheet1$]
IN 'C:\Users\GONZW053\Documents\My Desktop Documents\Monster Database Exports\DTPM - WDW DLR\book1.xlsx'[Excel 12.0 XML;HDR=No;]
(Sheet1$ is the range from the Excel file where you're moving things from)
As far as I know, this approach has relatively little overhead. Of course, moving around large files just takes time.

Recordsource vs Recordset for Unbound Forms

I am creating a application which uses Access ADP (Access Data Project). as the front-end and SQL Server as the back end. I am using ADODB for the connection. I have been doing some research as to whether to use the RecordSource property or Recordset property for forms. My goal is to create an unbound application.
I haven't been able to get a clear answer on which one to use. So far, what I have been able to do is set the recordsource to the stored procedure like this
strSQL = "exec STOREDPROCEDURE "
Me.Form.RecordSource = strSQL
I can also open the same SQL str as a recordset, set the forms recordset then close the recordset like this
Dim Cmd As New ADODB.Command
Dim rs As New ADODB.Recordset
Set rs = New ADODB.Recordset
strSQL = "exec STOREDPROCEDURE"
rs.Open strSQL, CurrentProject.Connection
Set Me.Recordset = rs
rs.Close
Can someone explain to me what the differences are between the 2 and which is the preferred method? The way I see it, the data is getting filtered on SQL Server before being passed back to the application, so I am not seeing the difference between using Recordset or Recordsource.
With an .adp, you will use record source, not recordset, though you may depending on what version of access you are running, need also to set the input parameters property as well.
Me.RecordSource = "EXEC schema.storedprocedue [arguments]"
will work fine for forms.
One comment I would make however is - why an .adp? MS Access 2013 & Later will not run an adp, and Access 2010 is likely to become unsupported in another couple of years.

Show Users on Access Database

I am trying to show all the users that is currently on my Access database. I am using a VBA code that I found online and am trying to modify it to my needs. I am trying to get all the available users and display it on List Box on my form called "ListUsers".
The code is able to output to the debug window but I'm unable to update my list box. I get the following error: "Run-time error '6014': The RowSourceType property must be set to 'Value List' to use this method." I looked on the property window for that list box and couldn't find anything related to RowSourceType. I have tried a few different suggestions online but I am still unable to update the list box, so I wanted to see if anyone here may have some ideas. My code is below, I placed the VBA code on a button click.
Option Compare Database
Option Explicit
Private Sub cmd_Users_Click()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.recordset
Dim i, j As Long
Set cn = CurrentProject.Connection
' The user roster is exposed as a provider-specific schema rowset
' in the Jet 4.0 OLE DB provider. You have to use a GUID to
' reference the schema, as provider-specific schemas are not
' listed in ADO's type library for schema rowsets
Set rs = cn.OpenSchema(adSchemaProviderSpecific, _
, "{947bb102-5d43-11d1-bdbf-00c04fb92675}")
'Output the list of all users in the current database.
Debug.Print rs.Fields(0).Name, "", rs.Fields(1).Name, _
"", rs.Fields(2).Name, rs.Fields(3).Name
While Not rs.EOF
Debug.Print rs.Fields(0), rs.Fields(1), _
rs.Fields(2), rs.Fields(3)
ListUsers.AddItem "'" & rs.Fields(0) & "-" & rs.Fields(1) & "'"
rs.MoveNext
Wend
End Sub
I figured it out... I had to set the RowSourceType on the code. I added the following to the button click event:
Me.ListUsers.RowSourceType = "Value List"
There is also a good post here:
Ms Access AddItem with VBA

Help Debugging this Code to Convert for .adp file type

I had a form with some VB code that was using Access 2003. Recently we wanted to use the same form as a small front end interface for another database that has a SQL Server backend. However, the file type for this project in Access is .adp and not all of the vb code is working properly. If you could help me fix the bugs in this code:
Private Sub SurveyNameCombo_AfterUpdate()
Dim db_CFC As DAO.Database
Set db_CFC = CurrentDb
Dim rst As DAO.Recordset, query As String, count As Integer
query = "SELECT DISTINCT SurveyID FROM tbl_SurveyMeta WHERE SurveyName = " & Chr(34) & Me.SurveyNameCombo.Value & Chr(34)
Set rst = db_CFC.OpenRecordset(query)
count = rst.RecordCount
If count > 1 Then
Me.SurveyIDCombo.RowSource = query
Else
rst.MoveFirst
Me.SurveyIDCombo.Value = rst.Fields(0).Value
Call SurveyIDCombo_AfterUpdate
End If
End Sub
It is throwing errors in the for the DAO.Database and DAO.Recordset.
Thank you for your help!
The error message "User-defined type not defined" on a line such as this ...
Dim db_CFC As DAO.Database
... means your application doesn't include a reference to the Microsoft DAO Object Library.
Open a code module, then check from the main menu in the VBE editor: Tools->References
Ordinarily the cure would be to place a check mark in the box next to Microsoft DAO Object Library, then click OK. However, your application is an ADP, and I don't know whether DAO can even be used in ADP. You can try. :-)
Sorry I can't tell you more. I quit using ADP a few years ago. Instead I use the MDB format with ODBC links to SQL Server database objects. Perhaps you could consider the same approach if you're unable to get the ADP version working as you need.