Modules & VBA :: Access 2010 And ADODB Recordset Count
Nov 24, 2013
I opened a 2007 Access db in Access 2010. This DB worked perfectly in Access 2007, but when I opened it in 2010 my recordset.recordcount no longer works.
This is what I have:
rsGetInst was previously defined
Dim intInstCount as integer
Dim rsGetInst As New ADODB.Recordset
rsGetInst.CursorLocation = adUseClient
rsGetInst.CursorType = adOpenDynamic
rsGetInst.LockType = adLockOptimistic
rsGetInst.open "Select * from tblInstruction where CustID = " & intCustomerID
intInstCount = rsGetInst.recordcount
At this point a get a "type Mismatch" error, and it is happening in all my recordsets recordcount.
Is there a command or reference that needs to be change when using Access 2010. When I compared the references the only difference is that in 2007 we reference Microsoft Access 12.0 Object Library and in 2010 is Microsoft Access 14.0 Object Library.
I'm building a lab environment into one of my projects. I'm testing the distribution of values over a largish number of attempts to create a unique value.I have a table called LAB_UniqueIDTest, with two fields:
LAB_ID - the string value being tested, and LAB_UsageCount - the number of times the value has been created.
I'm trying to open the table using the following code:
Code:
' Initialize access to the LAB_UniqueIDTest table Set rs = New ADODB.Recordset rs.Open "LAB_UniqueIDTest", _ CurrentProject.Connection, _ adOpenKeyset, adLockOptimistic
I have similar snippets of code all over the application - either with a literal (as here) or as a string parameter.I do not, ever, use the options parameter of rs.open.I get error message "Run time error -2147217900 (80040e14) Invalid SQL statement - expected DELETE, INSERT, PROCEDURE, SELECT or UPDATE
My guess is it's because somehow the Open procedure is trying to interpret the tablename as a SQL statement. But how come it isn't this obtuse at other times?
I can't make edits with ADODB recordset bound to my form.
Access 2010 linking to SQL Server 2008.
Simple form bound to a single table.
Connection string works fine.
Code is as below (cursor etc is set using enums btw).
Private Sub Form_Open(Cancel As Integer) Dim rst As ADODB.Recordset If g1OpenRecordset(rst, "tblName", rrOpenKeyset, rrLockOptimistic, False) = False Then Cancel = True Exit Sub
I have a routine which connects to MySQL database with ADODB connection. This worked in 2003 and 2007 runtime but throws a 430 error on 2010 runtime. It works in full access 2010. Has there been a change of policy to restrict this type of connection in the 2010 runtime? If I use a linked ODBC table instead of ADODB the runtime fails with "Runtime Error". It still works in full access.
ADODB.Recordset (0x800A0BCD) Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.
Code: <% function combomaker(elSQL, elFieldNameID, elFieldName, elSelected, elConn) ' This function creates a generic combo box with values from a table dim elRS set elRS = server.CreateObject("ADODB.Recordset") set elRS = elConn.Execute(elSQL) elRS.MoveFirst
do while not elRS.eof response.Write "<option value='" & elRS.fields(elFieldNameID) & "'" if elSelected <> "" then if cstr(elRS.Fields(elFieldNameID)) = elSelected then response.Write " selected " end if else if elRS.BOF then response.Write " selected " end if end if response.Write ">" & elRS.fields(elFieldName) & "</option>" & vbCrLf elRS.MoveNext loop elRS.close set elRS = nothing end function %>
I have a form that shows records from ADODB recordset.When I try to apply filter to the underlying recordset it works all right but the form doesn't reflect the changes. It shows same rows as before filtering. In debug I can see that the recordset contains only filtered records. Me.Refresh (Recalc, Requery) doesn't work.
Code is as follows:
Dim rs As New ADODB.Recordset rs.Open sql, conn, adOpenStatic, adLockOptimistic Set Me.Recordset = rs
Sub combo_AfterUpdate() Me.Recordset.Filter = "CompanyNo = 123" End Sub
The form is in Continuous forms mode. I cant use DAO because the data comes from SQL server user-defined function.
I have the listbox named "payment_date", which shows recordset specified by following code:
Code: Private sub Form_Current() Dim que As String que = "SELECT [date] FROM payments WHERE id Like '" & Me!myid & "*' ORDER BY [date] desc;" Me.payment_date.RowSource = que End Sub
I need my listbox to show recordset with record count like this:
I'm trying to write a query to get a count of Volunteers under a certain Job Code for a given year - problem comes in that a single Volunteer may record hours multiple times under a Job Code in a given Fiscal Year. I can't seem to get "Unique Values" to work. From my research it looks like I need a two-part query but (as a newbie) I'm not quite sure how to write that. I have two queries, one that works and one that doesn't.
This one counts total amount of hours volunteered under a given Job Code, it works:
Code: SELECT tblHoursWorked.FiscalYear, tblHoursWorked.JobCodeLookup, Sum(tblHoursWorked.HoursWorked) AS [Sum Of HoursWorked] FROM tblHoursWorked GROUP BY tblHoursWorked.FiscalYear, tblHoursWorked.JobCodeLookup; HAVING (((tblHoursWorked.FiscalYear)=[Enter Year:]));
This one attempts to count number of Volunteers that worked under each Job Code in a given year - it instead counts number of entries under that job code. What I think I need to do is count unique instances of the NamesIDFK, but I can't seem to get that to work.
Code: SELECT DISTINCT tblHoursWorked.[JobCodeLookup] FROM tblHoursWorked GROUP BY tblHoursWorked.[JobCodeLookup];
1) correcting my second query and 2) putting them into one query so I can use them in a report.
I try to use collection of a ADODB.recordset eg rsTarget,Essentially I want to assign the fields (columns) in this rsTarget with respective data. I tried to use of
two sets. (fld as adodb.field) Set fld = rsTarget.Fields.Item(count) Set fld = rsTarget.Fields.Item(Column(count))
Then I try to use following to assign RsTarget!fld.name = Data1
It failed stating that there is no fld.name. Using column set, it state that there is no column function. How to do it right?
Hi everyone, I'm just a newbie in DB programming and I'm having a trouble:
I have a database located in my IIS server: "c:inetpubwwwrootwebapplication1dbs1.mdb".
I'm also developing a VB6 app in another computer which will access to my IIS server to get data in my database. I'm using ADODB, but I don't know how to establish the connection as well as to get the data from the server (remote machine).
Can anyone in here help me by showing an example in VB6 code? Thank you very much, any sugestion is welcome Reply With Quote
I am trying to create a process which selects a customer's site identifier and uses that to query an Oracle database through an ADODB connection. Which is all well and good until that customer has more than one site.
Here is a simplified version of what I have created:
Code:
'Get site details from current database on basis of company selected on form
Dim cnn As ADODB.Connection Set cnn = CurrentProject.Connection Dim RsSites As New ADODB.Recordset RsSites.ActiveConnection = cnn
[code]....
As I said, this works perfectly when the customer only has one site, but I have failed to find a way to turn a recordset with multiple values into a SQL variable that can be used in the IN clause.
I have attempted to convert the recordset to a string using GetString, but could not find a way to correctly seperate out the records.
I have the following code which successfully opens the dialog box with filters however when I add a function with an Excel import, the filters do not work at all (no files are shown even though they exist in the directory that's opened within the dialog box). If I manually type in the filter (i.e. *.x) it still shows the files.The function at the bottom was provided by cheekybuddha from another form, I'd be lost on getting the Excel file imported into Access.Here's the VBA code (the Function is also included at bottom):
Code: Private Sub Command0_Click() On Error GoTo PROC_ERR Dim strpathtofile As String Dim strTable As String, strBrowseMsg As String Dim strFilter As String, strInitialDirectory As String Dim blnHasFieldNames As Boolean
I have an application in Access 2003. It uses VBA to open an Excel file. The file has one tab for charts and one for data. The program counts how many charts needs to be created, one per project. It then will place 4 charts per tab, creating as many chart tabs as necessary, keep one data tab. The program then writes the data and links the data to the corresponding chart. It will also write legends, and scale the charts. This all works fine under Access 2003/Excel 2003.The error I get is "Application-defined error or object defined error".The line that gives me the error is: Set chCopy = xlsheet.ChartObjects(idx).I am using the Multi-Chart option frmChartType = 1
Now I'm moving to the Office 2010 world. It is not working. Below is the code I run to do the magic. I guess something is happening in Excel 2010 that is different from 2003.I found when I comment out the error line, and other lines dependent on chCopy it creates the charts, but all the charts are pictures and not charts!!
Code: Public Sub GenerateChart() ' Generate an Excel chart Dim db As Database Dim rst As DAO.Recordset Dim xlapp As Object
I would like to update the following code I have been using to send emails, from Access 2010 via Outlook 2010, to include my signature block with hard returns in between each line and a few above the signature.
Lets say the signature would be: My Name My Company Name My phone number My Reference
I tried next to: stMessage = Me![EmailMessage] &"My Name" & Chr(10) & Chr(13) & "My Company Name"
etc.
It does not work..
Here is the coding :
Code: Private Sub SendEmail_Click() On Error GoTo ProcErr Dim stLinkCriteria As String
Here is my project: For a duty plan the employees are assigned to positions in a certain area.
For example: Name. Position. Description. Map Brown. 1. backdoor. 1 Miller. 3. frontdoor. 1 Norman. 4. left wing. 2 Hoover. 6. right door. 2 ....
Now I want to show the positions within circles on the maps, with the names within dynamically, as the employees change every week.
The coordinates of the positions do not change, but not every position is needed in every duty plan.
So, my idea is to draw all possible shapes on all possible maps and make them visible or not depending on the assignement.
The duty plan is my table in access and looping through all records I would like to fill the needed shapes.
All maps are on slides (40 slides and about 400 positions) and should be filled accordingly.
I can open my presentation, although I only could do it by late binding ( a reference to ppt 14 obj. Lib fails with an error!! - why??) but I cannot any solution how to loop through the records and do the job.
I want to enable a few fields when i click on the Add button on my form.I have change the onclick to Event Procedure to be able to add the following code
Code: Category_Desc.Enabled = True
My Category_Desc field get enable as expected but the Add button no long work
Code: Private Sub add_Click() Category_Desc.Enabled = True Me.Refresh End Sub
I have a normal Access table. The first column is ID and is the primary key. The second column is a text. The table consists of two records and is sorted in ascending order. First comes the data set with the ID 1.
Sub test() Set rs_access = CurrentDb.OpenRecordset("tab1") rs_access.MoveFirst MsgBox (rs_access.Fields("id").Value) End Sub
The message box shows 1. So everything is fine. Now I sort the table descending. But I get the same message. Why? Appearently the recordset doesn't know that the table was modified. The recordset should register that the table is modified.
The following code browse from one form to another and shows the record details I select in the first form which is what I need, however, the problem is it only shows that record and will not allow me go to next or previous records when pressing NEXT or PREVIOUS by saying this is the First Record or this is the Last Record.
Anyway to modify it to allow me navigate to other records.
Dim txtJobNumber As Integer Private Sub Job_Number_DblClick(Cancel As Integer) 'Store Job_Number in txtJobNumber variable and display message to show value. txtJobNumber = [Job_Number]
I have a database that, I would like to add a button that performs a active directory lookup. I would like it to check a username with Active Directory, and auto populate a few fields.
First Name Last Name Manager Department
This is my first database and I have very little exp using VBA.
how to make this two fields in my form to say Y or N if the field is Not Null. Like if the field is not null = Y Else = N for the two fields. I have a picture to show what i'm talking about.
I have always had solid read access to the Windows registry running on Windows XP with Access 2007. I am utilizing code from here in a separate VBA Module to obtain access to the Windows registry:
"Change registry settings in VBA"
[URL]
On Windows 7 x64 / Access 2010 x86, I am seeing a 0 value in lngKeyHandle. Also, m_lngRetVal has a value of 2 after the RegOpenKey LOC.
Code: ' -------------------------------------------------------------- ' Query the key path ' -------------------------------------------------------------- m_lngRetVal = RegOpenKey(lngRootKey, strRegKeyPath, lngKeyHandle) ' -------------------------------------------------------------- ' If no key handle was found then there is no key. Leave here. ' -------------------------------------------------------------- If lngKeyHandle = 0 Then regQuery_A_Key = vbNullString m_lngRetVal = RegCloseKey(lngKeyHandle) ' always close the handle Exit Function End If
I have verified that I have the key successfully in the registry... installed via the .reg file that works on Windows XP / Access 2007 systems.
I have a split db with tables in the back end and my forms, reports, code etc. in the front end.
I encrypted the back end with a password. That worked fine.
I deleted and relinked my tables to the encrypted back end. That worked fine as well.
I have a function that will disable the shift key bypass. If I run that in my front end db then I can't save it as an accde because I can't get to the HOME screen. If I save it as an accde first then I can't run my 'disable shift key bypass' function because I can't get to the modules!
How can I secure a split Access 2010 database so that the user cannot execute shift bypass on the front end or make any changes to the code?
Previously in Excel / Access 97 / 2003 I made a little tool that would search for files in specified locations - I modified the code so that it would search for files based on what was entered in cells.
I believe a lot of the old code doesn't work in Access 2010 and it seems like a lot of the old file searching code I used to use no longer works.
Is there code available that searches a directory and lists results?