Classic ASP, Visual Basic, and ADODB Recordsets - ms-access

I've recently inherited a classic ASP application written in Visual Basic and Java Script. I'm not a programmer but have written a few applications in VBA working with Excel and Access.
I'm looking to add in a script to copy an excel (.xlsx) worksheet to an access (.accdb) table using ADODB recordset. I've used this approach in VBA but the Visual Basic Code in asp classic is not recognizing the Locktype or Options properties of the recordset object. If i remove .Options and .Locktype the script will run but only in read only mode and I can't add new records.
adPath = Server.Mappath("OutageData/QHT.accdb")
Set cnnAccess = Server.CreateObject("ADODB.Connection")
with cnnAccess
.Provider="Microsoft.ACE.OLEDB.12.0"
.Open adpath
end with
Set rstAccess = Server.CreateObject("ADODB.Recordset")
with rstAccess
.ActiveConnection=cnnAccess
.CursorType=adOpenDynamic
.Options=adCmdTable
.LockType=adLockOptimistic
.cursorlocation=aduseclient
.Open "TST1UPDT"
end with
Any suggestions?
Thx
Keith

ssqlinsertupdt ="INSERT INTO " & "TST1UPDT" & " SELECT * FROM " & "[Excel 8.0; HDR=YES; DATABASE=" & cnnAccess & "]." & "[TASK$]"
DatabaseConnection.Execute ssqlinsertUpdt
The sql statement above worked.

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.

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.

Ms Access 2010 - Triggering a SSIS package - Runtime Error

I have landed in what I call a "wierd" situation. I have this snippet of code, which is used to trigger a SSIS package at stored in a particular location :
Dim sDTSfile As String
Dim dtexecStr As String
Dim sSourcePath As String
sSourcePath = "source path location"
sDTSfile = "dtsx package location"
dtexecStr = "dtexec /f """ & sDTSfile & """ /set
""\Package.Variables[User::Directory].Properties[Value];" & sSourcePath & """"
Set WshShell = CreateObject("WScript.Shell")
This snippet runs good in MS Access 2007, but as apart of the upgrade to MS Access 2010, I was testing the functionality of the code, and the code burps at this point
WshShell.Run dtexecStr, 1, True
Is there something that I am doing wrong in this case, If yes, ideally when the code is working in 2007, it should be functioning good in the upgraded 2010 even.
Thank you in advance!
The error meesage:
Method 'Run' of Oject 'IWshShell3' failed. Runtime error - 2147024894 (80070002)

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.

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

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.