Modules & VBA :: Finding Last Record (QueryDef Or Recordset Method)

Feb 11, 2014

My question is which method of finding the last record is best, QueryDef or Recordset? Here is my data:

Table:
tbl_module_repairs

Field:
aps_rma

Textbox to insert last record RMA into:
txt_test

Here is some code I tried but get an invalid argument msgbox:

'''''''''''''''''''''''''''''''''
'Opens last RMA into textbox (For opening tag sheet)
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
'Get the database and Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tbl_module_repairs")

[Code] .....

View Replies


ADVERTISEMENT

Modules & VBA :: Edit Recordset Querydef That Has Calculated Field

Jan 19, 2014

Is it possible to add/edit a record from a DAO querydef that has a calculated field in.

Code:

Set qdf = db.QueryDefs("qryOutput_" & strDept)
qdf.Parameters("Enter Date") = dDate
Set rs = qdf.OpenRecordset()

Using the rs.Edit or rs.AddNew worked fine until I put a calculated field in the query.

The calculated field is just a total of some fields in the table.

I thought this was something to do with dbOpenDynaset but it just keeps having the same error

Cannot update. Database or object is read-only.

View 3 Replies View Related

SQL Statement For ADODB Recordset.filter Method

Feb 8, 2007

I want to use the NOT IN operator for the filter method of ADODB.recordset in VBA. Do anybody in the forum know the syntax.

View 3 Replies View Related

Modules & VBA :: Add WHERE Clause To Query (queryDef)

Dec 1, 2014

I have a TRANSFORMED query:

Code:
TRANSFORM nz(count(T_qa.qaQAPK),0) AS SumOfQAs
SELECT month(qaDate) AS QAmonth, Count(T_qa.qaQAPK) AS QAs
FROM Q_ALL_qa
GROUP BY Month(qaDate)
PIVOT month([qaDate])
IN (1,2,3,4,5,6,7,8,9,10,11,12);

This query is record source for a report, then this report show all calculations in a form.

I have 7 of each (query + report) all showing on the same form.

All those queries calculate data for all departments.

In the form, I have placed a combobox.

What I want is to create a vba code which will add clause WHERE to all queries at the same time and then run it.

Code:
WHERE qaDeptFK=Forms!F_CompLvl.cboDeptStats

However, if nothing has been selected in the combo, I want the queries to calculate data as normal, for all departments.

Where do I place the vba statement? Is it under combobox AfterUpdate event?

I am planning to use this: (As I never done it before)
[URL] ....
Modifying SQL On-The-Fly section

View 5 Replies View Related

Modules & VBA :: QueryDef And Export To Excel

Jun 13, 2014

So I had this code working and then I cleaned it up a little and it no longer works. It should export data from a created query using criteria selected by the user on a form and put it into an excel file that exists. I get no errors but it does not export anymore. After pouring over it for a while checking for mistakes with my form control references and variables I have yet to find anything. I did change my form name and edited the code accordingly after I already had it working, and changed a few form settings but changing them back did not fix the issue. I am not very experienced and stumped since I am not getting error messages.

Code:

'First set variables for the SQL string and CreateQueryDef command
Dim strExport As String
Dim qdf As dao.QueryDef
'Then define the SQL to be exported (Static Response Info by ItemID)

[Code] ......

View 6 Replies View Related

Modules & VBA :: Finding Duplicates In A Table And Recording Values In That Record

May 2, 2014

I've been looking everywhere to find a better way of finding duplicates in a table and then recording and adding another value in that record together.

Let me try to explain better.

example:

I have a table that has 2 columns "Name", "DOB". I would like to find all duplicate "DOB" and add all of the "Name"'s together.

Quote:

Name DOB
bob 19800201
Sam 19761211
Jim 19800201

The output I would like is to have Name = bob & Jim DOB = 19800201.

I've tried using the find duplicate wizard in access but I can't seem to group them together and just to find the duplicates it takes upwards of a minute.

View 1 Replies View Related

Modules & VBA :: Why RecordSet Not Starting From Record 1

Sep 1, 2014

Why my Recordset start from record # 301 instead of # 1 Here's part of my code:

Set db2 = CurrentDb
Set rst2 = db2.OpenRecordset(strTable2)
If rst2.RecordCount = 0 Then
MsgBox "No records to process."

[Code] ....

Table has 12,000 records and the first record has an ID of 1. So why is it starting from the record 301? What am I doing wrong?

View 3 Replies View Related

Modules & VBA :: Lookup A Record In Recordset

Oct 17, 2014

I am trying to lookup a record in a recordset. If no match is found then run an append query. I am having trouble coding the findfirst syntax.

Code:
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim WO As String
WO = Forms!frmdsh_workorder!txtWO
Set db = CurrentDb

[Code] .....

When I run the Function, it throws a RT error #3077 on the .findfirst line. (Syntax Error (Missing Operator) in expression. )

View 3 Replies View Related

Modules & VBA :: Filtering Form / Report - QueryDef Criteria Using OR

May 7, 2015

I have a form with 3 combo boxes that filter another form/report. The first combo (cboByCategory) contains options from 2 different fields within the same table. Before I added this add'l piece of code, all 3 combos worked fine. I am not getting error messages, it just does not filter on the other 2 combo boxes - cboDiv and cboGender.

Code:
Private Sub cmdModifyRecords_Click()
On Error GoTo Err_cmdModifyRecords_Click
Dim stDocName As String
Dim strFilter As String
Dim stLinkCriteria As String
stDocName = "Modify_OpenItems"

[Code] .....

View 5 Replies View Related

Modules & VBA :: Copy Current Record From Recordset To Csv

Aug 4, 2013

I have a DAO.recordset called "rsSQLIn". This comes from a csv file by:

Code:
strSql = "SELECT * " _
& "FROM [Text;Database=" _
& strFolder _

[Code]....

While the validation runs a boolean keeps track of validated input and errored input.

After validation the validated input is dumped in the table.

Now what I want is de saving the errored record from "rsSQLIn" to be copied to a new .csv file.

The problem I have is that I cant seem to get the current record from the recordset "rsSQLIn". How do I reference this? I need the complete set of 24 fields being the same within "rsSQLIn"

View 3 Replies View Related

Modules & VBA :: Recordset Loop Stuck On First Record

May 8, 2014

I am attempting to use 2 fields from a query to supply the Top and Left Properties of a Collection of Rectangle Controls on my form. The purpose of this is to display the locations on a map of "Spots" in a haunted house. The query that I am using shows the spots that have been pre-tagged with the location of where they belong on the map (currently the query has only 24 tagged spots). On the actual form I have rectangle controls (control type acRectangle) with their visible property set to False by default, named box1 through box25 (there will be more eventually, as I am just working with this test group).

I started with the following code, yet it stops after (correctly) placing the first spot on the map (please see the attached jpg):

Code:
Private Sub Form_Open(Cancel As Integer)
Dim ctl As Control
Dim db As DAO.Database
Dim rst As DAO.Recordset

[Code]....

I'm sure I need to have 'Loop' in there somewhere, but I am not sure exactly where to place it, or if another line is also needed.

View 10 Replies View Related

Modules & VBA :: FileCopy Command For Each Record In Recordset

Nov 5, 2013

I have a problem with trying to execute a command for each record in a recordset. What I'm trying to build is a file distribution system. I have a form with the path where the source file is and a subform with a couple of records where the destination path is defined. I use the code you will find below, but it will only copy the file to the destination from the first record.So the code will do the filecopy command for every destination.

Code:
Dim Sourcepath, Destinationpath
Sourcepath = Forms![Item distribution]![Item source path]
Destinationpath = Me.Destination_path
Dim rs As DAO.Recordset
Set rs = Me.Form.Recordset

[code]....

View 12 Replies View Related

Modules & VBA :: Generating Workbooks For Each Record In A Recordset?

Jul 18, 2013

Is is possible to generate a workbook for each record in a recordset, and title it using the unique identifier for that record?

I created the following code, but it does not seem to work. First of all it doesnt like the string and secondly it does not like the declaration of wb as Excel.Application

Code:
Private Sub generate_wkbk()
Dim rsID As DAO.Recordset
Set rsID = CurrentDb.OpenRecordset("Select * FROM tblMeeeting;", dbOpenDynaset)
With rsID
rsID.MoveFirst

[Code] .....

View 3 Replies View Related

Modules & VBA :: Copy Subform Recordset To New Record

May 8, 2015

I am trying to copy a subform record set from one record to the next record. The data in the main table is copied over using this method;

Code:

Dim v1 As Variant
Dim v2 As Variant
Dim v3 As Variant
Dim v4 As Variant

v1 = Me![Today's Date].Value
v2 = Me!Insured.Value

[Code] ....

Can I integrate the copying of the subform data to the new record with this or do I need something different, and if so what?

It's a many to many relationship and I've tried adding the following line to the code:

v5=Me![Endorsements Umb XS].[UmbID]
same=v5

and it works but it only copies the first record out of the set.

View 14 Replies View Related

Modules & VBA :: Print Current Record From Recordset?

Aug 7, 2015

Is there a way to print the current record from a dao.recordset?

This is an exercise to compare data content.

I have a table with 30 fields and thousands of rows (rs1).

I'm comparing it with a copy of the same table (rs2) that has the same number of fields and the same rows and almost the same content.

I can loop through the recordsets and get the cursor to stop on a field whose values don't match, lets say on row #x

and the programmed message will say something like:

"ROW: 699 Field: [RequestStatus] rs1.VALUE: Closed, DOES NOT MATCH rs2.Value: VOID, in the comparison recordset"Then I'd like to print the entire Row, Row #699.

I thought I could use rs1.getrows but I'm not sure how to make that work.

View 4 Replies View Related

Modules & VBA :: Query To Search For Records - Passing Parameters In A QueryDef

Aug 27, 2013

I have a query that searches for records that are between two dates using the WHERE clause. The two dates are referenced to two respective text boxes on a form. On the same form I have a button that will launch the query in VBA using querydefs. I get the error 3061 saying I need to input the parameters. Therefore I am a bit unsure how to set the parameters in VBA. So far I have done this:

Code:

Dim Db As DAO.Database
Set Db = CurrentDb
Dim QDef As DAO.QueryDef
Dim rst As DAO.Recordset
Set QDef = Db.QueryDefs("Rqt_F_BrokerageMandate_MF3_TEST")

[Code] ....

Where Date_VL is the field to be filtered. I know this is wrong but all examples I have seen have equated the parameter to a fixed value i.e 30/12/2012 for example, but I want this to be at the users discression. The only way I know of to get around this at the moment would be to write a temp query in VBA with PARAMETERS in the SQL code instead using the method above/

After this I'm going to assign the recordset to a matrix but that's a different story!

View 10 Replies View Related

Modules & VBA :: Loop To Update Recordset Only Reaches 1st Record

Mar 13, 2014

I found this code and have substituted parameters to suit my own needs however the loop is not working. Only the first record in my recordset (which is a test recordset of only 3 records) is being updated.

Also, for testing only, the edit or update being applied is trivial: Description = "WHITE RESIN". If i can get the loop to work I want to substitute higher functionality to the module.

Private Sub Update_Click()
Dim dbs As DAO.Database
Dim rsQuery As DAO.Recordset

Set dbs = CurrentDb
Set rsQuery = dbs.OpenRecordset("qryRmResin", dbOpenDynaset)

[Code] .....

View 14 Replies View Related

Modules & VBA :: List Box To Show Recordset With Record Count

Sep 22, 2013

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:

3.date
2.date
1.date

View 4 Replies View Related

Modules & VBA :: Formula Based On Record Number - Recordset Required?

Dec 14, 2014

In order to arrive at the required solution I have to perform a calculation, using data from each successive table record (in chronological order). The result of each calculation must then be used to arrive at the result for the next calculation.

In other words I have to update a variable based on data from each record, sorted in chronological order, and use the final result to populate a field on a form.

Is it time to break out my copy of "VBA For Dummies" and start learning how to use Recordsets?

View 8 Replies View Related

Modules & VBA :: Check If Record Already Exists In Recordset Based On 2 Conditions

May 27, 2014

I have a table in Access that I have a form saving new records to. Before this save occurs, I would like Access to check if the account number already exists and if the account does exist if it is outstanding. If both of those conditions are met I would like a message box to display and cancel the save as it is a duplicate. I can't seem to get it to work though.

I was thinking to use a filtered recordset based on one of the conditions and then perform a find on that recordset to see if it is null.

Code:

dim acct as long
dim rstfiltered as DAO.Recordset
Set rstfiltered = CurrentDb.OpenRecordset("SELECT * FROM tblclstrack WHERE [Request Status] <> 'Completed'")
acct = Me.cd_number.Value

[code]...

View 9 Replies View Related

Modules & VBA :: Run-time Error 3021 While Updating Existing Record In DAO Recordset

Jun 16, 2014

I have a linked table to a DB2 database. this table contains key-pair values and has about 140k records.

I use a Sub to update the value of a specific record.

The sub starts by opening the needed DAO recordset
Then it uses the rs.Findfirst method
It checks if rs.Nomatch is not true (so the records exists!)
Then it starts updating the record with
rs.edit
rs!value1 = myvalue1,
rs!value2 = myvalue 2
rs.Update
There is where I get the '3021 No current record' error

I use the same sub on the same table to update to different parts. One part works the other gives me the error.

I have checked for typos.

View 5 Replies View Related

Modules & VBA :: Recordset Adds New Record Into Subform But On Save Nothing Added To Table

Nov 5, 2014

I am adding new record into subform via recordsetclone method. The problem is that record is added but on save it does not appear in the table. If add this record manual using subform everything works. When record added manually update of the record works fine.

C
'Add Wastage value to flooring area section
Private Sub Wastage_AfterUpdate()
Dim rsFlArea As DAO.Recordset
Dim Wastage As Double
Dim Item As String
Set rsFlArea = Me.OrderFloorAreaEdit.Form.RecordsetClone

[Code] .....

View 6 Replies View Related

Modules & VBA :: How To Extract Recordset From Subform Into Recordset Object

Aug 14, 2015

Special situation: The SQL Server Linked Server across the country is linked to a Read Only Oracle DB. This data pull works perfectly and populates the Subform.

The problem is that Oracle can take 3 to 6 seconds to retrieve the single record depending on the network traffic through a small pipe.

The code below shows the RecordSource for the SubForm. clicking on a list box supplies the value. Then 3 to 6 seconds later, the subform populates.

The actual Recordset for this Recordsource is needed to conduct Validation on each field. Normally this would be on SQL Server, I might just create a Recordset Oject and run this SQL statement again in 1 milisecond. In this case, it will probably take an additional 3 to 6 seconds. Avoiding another lengthy round-trip to Oracle would be prefered.

Goal: How does one grab, clone, or other wise reference the existing recordset for the SubForm?

Note: Immediate Window - One single field can be returned quickly

There are 48 fields that need validation - is there a way to reference the entire recordset?

Immediate Window during Break Mode:
? me.fsubsrNavSHLBHL("NavSH_QQ")
NESE ' this is the correct value for the current recordsource

Set a breakpoint right after the line:
fsubsrNavSHLBHL.Form.RecordSource = "Select * from vsrNavigatorSHLBHL where Well_ID =" & txtNavWellID.Value

Immediate Window:
? me.fsubsrNavSHLBHL.Form.RecordSource
Select * from vsrNavigatorSHLBHL where Well_ID =91229

View 4 Replies View Related

What's The Best Method Of Duplicating A Record?

Feb 22, 2005

Hi,

I want to be able to make an exact copy of an existing record in a table and then change the value of a couple of the fields before writing it to the table as a new record.

What is the best way to go about this? I guess it is possible with select, update and append queries but I'd rather do it in code.

It sounds like it should be a simple and commonly performed exercise but I can't find anything on it.

Thanks in advance!

John

View 4 Replies View Related

Modules & VBA :: Can Use Result Of One Recordset For Other Recordset

Jul 7, 2013

I want to write a email where there are 2 or 3 different ordernumbers for same email, i want to include the email in the mail part as single column table. how to do it? also can i use result of one recordset for other recordset?

View 1 Replies View Related

Modules & VBA :: Run Python Method With Arguments?

Aug 18, 2014

I have a python script "runAll" that takes two arguments: processID (the primary key of one table as a string) and a filename (a full file name path as a string).

Is it possible to run a python method with arguments from inside a VBA script (activated by a button press)?

My python script is called XMLGenerator.py, and the method I want to run is called runAll(processID,filename).

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved