Creating A New Access Table From A Recordset
Jul 21, 2007
I'm experimenting in MS Access VBA reading from one MS Access application to another as visible in the code below. My problem is that I'm reading a recordset from an Access file and want to take that recordset (rec) to create a table in the current databank. If I run an cmd.commandtext "make table query" it runs the query across the connection and places the table in the remote database (as expected). Can I take the recordset and create a local table using ADODB command or is there a better approach. (I should note that the remote MS Access file does not have an .mdb suffix) Thanks in advance.
Sub get_indbyind()
Dim strInputfile As String
Dim dlgOpen As FileDialog
Dim bob As String
bob = Application.CurrentDb.Name
' select connection
Set dlgOpen = Application.FileDialog(msoFileDialogOpen)
With dlgOpen
.AllowMultiSelect = False
.Show
End With
strInputfile = dlgOpen.SelectedItems.Item(1)
' make connection
Dim cnn As ADODB.Connection
Set cnn = New ADODB.Connection
Dim strcnn As String
strcnn = "Provider=Microsoft.jet.OLEDB.4.0; Data Source=" & strInputfile
cnn.Open strcnn
' MsgBox "connection made"
' create recordset
Dim rec As ADODB.Recordset
Set rec = New ADODB.Recordset
rec.Open "SELECT * FROM SATransfers;", cnn
Dim n As Long
Dim i As Long
Do While Not rec.EOF
Debug.Print rec.Fields(0).Value; rec.Fields(1).Value; rec.Fields(2).Value; rec.Fields(3).Value
rec.MoveNext
Loop
' create table from connection cnn
Dim cmd As ADODB.Command
Set cmd = New ADODB.Command
Dim rs As New ADODB.Recordset
cmd.ActiveConnection = cnn
cmd.CommandText = "SELECT SATransfers * INTO tmp1 FROM SATransfers;"
Set rs = cmd.Execute
cnn.Close
Set cnn = Nothing
Set cmd = Nothing
End Sub
View Replies
ADVERTISEMENT
Oct 15, 2014
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.
View 1 Replies
View Related
Nov 25, 2005
hi
i am trying to write a query to produce a descending recordset of photo_id but only one from each user e.g
if these are the top records
photo_id 150 m_name dave
photo_id 149 m_name dave
photo_id 148 m_name dave
photo_id 147 m_name john
photo_id 146 m_name john
photo_id 145 m_name fred
i want the query to produce this
photo_id 150 m_name dave
photo_id 147 m_name john
photo_id 145 m_name fred
and so on, there are other fields also but that gives you the idea i hope.
what i have come up with is this
SELECT MAX(FORUM_ALBUM.Photo_id) AS ID, FORUM_ALBUM.Photo_Name,FORUM_ALBUM_USERS.M_Name,FO RUM_ALBUM.Member_id
FROM FORUM_ALBUM, FORUM_ALBUM_USERS
WHERE FORUM_ALBUM.Member_id=FORUM_ALBUM_USERS.MEMBER_ID AND FORUM_ALBUM.Photo_Status=1
GROUP BY FORUM_ALBUM.Photo_id,FORUM_ALBUM.Photo_Name, FORUM_ALBUM_USERS.M_Name, FORUM_ALBUM.Member_id
ORDER BY FORUM_ALBUM.Photo_id DESC;
this gives me the records i want in the correct order but it gives multiple instances of each M_Name instead of just one record for each M_Name
i hope i have explained this clearly enough
thanks
Dave
View 2 Replies
View Related
Apr 17, 2015
I've done some basic work with arrays.. writing array data to form list objects.. How to use an array as a data source for a report?
Would i need to create a recordset and populate it with the array, then bind the report to it ?
The reason I am asking is the previous developer here built every app using arrays and UDT's... the apps are completely disconnected from the data. Everything is loaded in to arrays..
View 2 Replies
View Related
May 9, 2006
Hi all,
I write a program which is querying some data from a MS-Access database.
The problem here is, that the tablenames contain characters like "/" or "-" and I
do not want to change these names, because I think that the database
structure will be damaged.
To solve this problem I thought of creating a view to the table. I tried creating
this with a SQL statement, but that did not work.
Is there any other possibilty to create a view on a MS-Access table?
Regards,
Stefan
View 2 Replies
View Related
Feb 5, 2008
Hi,
I am trying to create a series of MS access tables from within a SQL 2000 DTS package. The names of the tables reflect the date range of the data within them. Creating the "Create table ddmmyy ...." statement isn't a problem (full code below), but doesn't run as it creates a Jet error - "Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'. Does anyone know if what I'm trying to do is possible.
Before anyone suggests it, yes I have posted this on SQL server forums.
declare @TheName char (8)
,@Cmd char (500)
select @TheName = (select max(LastRunDate) from NSP_Analysis_Dates)
select @Cmd = 'CREATE TABLE `NSP_Analysis_' + @TheName + '` (`TYPE` VarChar (200) NULL, `VENDOR_NO` VarChar (10) NULL, `VENDOR_NAME` VarChar (50) NULL, `AMOUNT_CLAIMED` Currency NULL, `REGION` VarChar (100) NULL, `CLUSTER` VarChar (100) NULL, `PLANT_CODE` VarChar (15) NULL, `PLANT_NAME` VarChar (50) NULL, `DATE_OF_SERVICE` DateTime NULL, `STATUS` VarChar (200) NULL, `TICKET_NO` VarChar (20) NULL, `NOTES` VarChar (255) NULL, `DATE_ENTERED` DateTime NULL, `AuthorisedByName` VarChar (50) NULL)'
sp_executesql @Cmd
View 1 Replies
View Related
Mar 6, 2008
Hi i hope someome can help. I am importing a data into a table, records are being rejected as they should due to validation rules. However access is not creating a table of rejected records. What am i doing wrong.
Thanks for any help
View 4 Replies
View Related
May 6, 2008
I have currently been given a task to re-work some current coding within Access. This is well above my understanding of Access and was hoping to get a little assistance with some simple coding language.
The database I am manipulating has data collected from tourists about their destinations and origins.
I wish to create 2 tables based on a current table. One table will be short trips (trip length <= 150km) and the other long trips (trip length < 150kms)
I wish for these tables to be created from a table of raw data upon the click of a button (GUI interface).
If you are puzzled by my question. I'll try to make it simplier by asking:
1. what line of code will create a new table overriding old
2. what type of code is required to create this table with specific column headings?
3. How do I import information from current available tables with the condition: 'Row Y' is > X
View 3 Replies
View Related
May 22, 2013
I am trying to create an access table linked to an excel file.
The excel file has 256,000 kb, 15 columns, 6,400 rows.
When I go to CREATE, DESIGN VIEW in access and try to create the new linked access table i get this message -
"MICROSOFT ACCESS HAS ENCOUNTERED A PROBLEM AND NEEDS TO CLOSE". I click on Ok and then it says "REPAIR MY OPEN DATABASE AND RESTART MS ACCESS".
I click on OK and then save the back up file. The file disappears. I start over again and the same process starts again and again...
View 14 Replies
View Related
Mar 27, 2014
I have just upgraded from Access 2003 to 2010. Now I'm trying to relearn some of the small things I used to be able to. In 2003, I could just have a table highlighted and select "Insert, Query". It would then open a query design with that table. Is this possible to do this in 2010? Or do you have to open query design then add the table manually?
View 2 Replies
View Related
Oct 10, 2007
Hi all,
I have a text source file and inpul layout i.e. field names start and end positions in excel file. I want create a table in access from the text data using excel file layout.
Can you please help me out in this. I am a mainframe programer and recieved an request to work in access.
View 1 Replies
View Related
Aug 14, 2006
Can anyone help me to create an accumulative balance in a table if the invoice is the same. For example:
Inv # Transaction Amount Balance
123456 10 10
123456 20 30
123456 15 45
321654 10 10
321654 35 45
321654 10 55
Thanks
View 2 Replies
View Related
Jun 24, 2014
Is there a way that i can put an ADODB.recordset in a new table using VBA in MS access 2013? The record set is dynamic, hence a new table should get created every time.
View 1 Replies
View Related
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
May 14, 2007
I'm trying to find the intersection of recordsets that result from two SELECT queries, but (to the best of my meager knowledge) Access doesn't support the INTERSECT clause.
Are there alternative ways to perform this operation in a single query? I read a few posts that suggested LEFT JOIN, but I am not sure about how to combine a left join w/ the inner joins I am using to retrieve my data.
My SQL statement would read as follows if Access supported INTERSECT:
~~~~
SELECT * FROM
(Table1 INNER JOIN Table2 On Table1.A = Table2.B)
INNER JOIN Table3 ON Table2.C = Table3.D
WHERE (Table1.X = True) AND (Table3.Y = True)
INTERSECT
SELECT * FROM
(Table1 INNER JOIN Table2 On Table1.A = Table2.B)
INNER JOIN Table3 ON Table2.E = Table3.D
WHERE (Table1.X = True) AND (Table3.Y = True)
~~~~
View 2 Replies
View Related
Jul 9, 2005
In a Library database, there is a form about Books Lends o returns (table: MovBooks) When someone needs a books, I need verify if the book is lended or not. (Table: Books, field: Status -Yes/No-) and update if its free
I want to resolve this problem using Recordset.
Thank you very much
View 2 Replies
View Related
Oct 28, 2004
hello there,
just curious if it was possible to populate an empty tables' fields from a recordset that had been defined earlier in VBA under the criteria of a bit of sql code?
cheers.
View 2 Replies
View Related
Mar 27, 2007
Hi,
I'm trying to create a new table from another existing two in vba. I'm using this code without success... Any help will be gratefully taken.
---------------------
Dim strSQL as string
Dim tablaSuma As DAO.TableDef
Dim rst As DAO.Recordset
strSQL = "SELECT * FROM Necesidades_TRS1, Pedidos WHERE Pedidos.Código=Necesidades_TRS1.Código"
Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenDynaset)
Set tablaSuma = CurrentDb.CreateTableDef("TablaSum")
For Each Campo In rst.Fields
tablaSuma.CreateField(Campo.Name, DB_SINGLE) = Campo
Next
----------------------
Mike
View 8 Replies
View Related
Oct 20, 2004
I have rather complex select statement (at least for me) that produces a summary of how a team scored in a league competition that week. I would not even worry about this issue, except that people float around as alternates and I deduced it would be easier to compute and store scores for a team the week they shot with a given group of people versus keeping track of who shot on what team over a 10 week period.
The selection takes 40 individual scoring records and consolidates them into 10 team summary records. I have verified that the query works, but implementing it has turned into a problem.
Problem one: my knowledge of recordsets is almost purely theoretical at this point, having never worked with them. Therefore commands and structures are a problem - mainly, I'm not sure what code is needed to post a recordset to a table
Problem two: the select statement that works as an Access query is bombing in VB
My code to date:
Dim RS As Recordset
Dim DB As Database
Dim strSQL As String
Dim inpWeekNum As Integer
inpWeekNum = 0
'InputBox "Enter Week Number" 'eventually request week number from user. an integer from 0-9
'strSQL = "SELECT tblRoster.* FROM tblRoster WHERE (NIGHT = 'Fri');" 'a test str. this worked.
strSQL = "SELECT tblRoster.TEAM, tblScores.WeekNo, " & _
"Sum([A1T1]+[A1T2]+[A1T3]+[A2T1]+[A2T2]+[A2T3]+[A3T1]+[A3T2]+[A3T3]) AS TeamTotal," & _
"Sum([A1T2X]+[A1T3X]+[A2T2X]+[A2T3X]+[A3T2X]+[A3T3X]) AS TeamXs" & _
"FROM tblRoster LEFT JOIN tblScores ON tblRoster.HEDR = tblScores.HEDR" & _
"GROUP BY tblRoster.TEAM, tblScores.WeekNo HAVING (((tblScores.WeekNo)=0))" 'hardwired week number
' "GROUP BY tblRoster.TEAM, tblScores.WeekNo HAVING (((tblScores.WeekNo)=inpWeekNum))" 'user prompted week number
Set DB = CurrentDb()
Set RS = DB.OpenRecordset(strSQL)
Do While Not RS.EOF
'Appending Code here... 'obviously missing code, but I know that it does cycle through as I would expect it to.
RS.MoveNext
Loop
'This was a previous test based on a canned qry I had saved (that resembles the above qry.
' this successfully posted, but only one record
'DoCmd.RunSQL "INSERT INTO [tblTeamScores](TeamNo, WeekNo, TeamTotal, TeamXs) " &_
' "VALUES (" & TEAM & ", " & WeekNo & ", " & TeamTotal & ", " & TeamXs & ")"
The select statement correctly produces this output in Access (for Week 0):
TEAM WeekNo TeamTotal TeamXs (how does one properly post a table in this interface?)
1 0 2397 182 0 3152 333 0 3292 664 0 2014 135 0 2836 186 0 3652 577 0 2024 198 0 1108 29 0 2630 2210 0 1977 11
Anyone out there have some suggestions? Am I even on the right track?
Thanks.
-Brian.
View 7 Replies
View Related
Feb 25, 2007
Hi, as you can see I'm up early trying to sort this one. I created a database on my PC (Access 2003) on one network, then converted it on my PC and transferred it via CD to another (PC and network, Access 2000). Due to problems I wanted to create a new database on the new machine and take all the tables, forms etc from the old database.
However, having done this when running the code it stops when it reaches the recordset. The current references I have are VBA, DAO 3.6, ADO 2.7, Ole Automation, and Access 9.0 library.
Help much appreciated.
Richard
View 1 Replies
View Related
Jan 16, 2014
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.
View 5 Replies
View Related
Jul 2, 2013
Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.In Excel 2007 and Access 2007, from Excel I deleted every RecordSet, rs.
Code:
rs.MoveFirst
Do Until rs.EOF
rs.Delete
rs.Update
rs.MoveNext
Loop
I then am trying to reenter the new data contained in Excel but it will not let me due to the above error. How do I write over the deleted RecordSet (#Deleted)?Here is my code(my connection string works fine):
Code:
rs.MoveFirst
For k = 1 To Sheets("2013").Cells(Rows.Count, "A").End(xlUp).Row - 4
rs!Index = Sheets("2013").Cells(k + 4, 1).Value
rs!DatePaid = Sheets("2013").Cells(k + 4, 2).Value
[code]....
View 3 Replies
View Related
Apr 13, 2005
HI all
I have form containing some filtered records. What code do I need to put on a button to trigger a make-table query; the make-table thus containing only the current filtered records (not the entire database).
The following will use the entire database:
Dim stDocName As String
stDocName = "qryMakeTableCompanyID"
DoCmd.OpenQuery stDocName, acNormal, acEdit
Thanks
John
View 1 Replies
View Related
Feb 25, 2006
Hi all,
I have a form with around 10 checkboxes which serve as a filter option...now, when I hit my cmdFilter button it works well with a simple MsgBox !Ime showing all the filtered names...now, I want to put the results into a table tblTemp so that I could show the results in my subform. I've tried with making a sql string something like "INSERT INTO tblTemp..." but it's still empty.:confused:
Since this table will serve as a one time data, I will need to delete all records when I hit the Filter button next time...so, how do I send my recordset data into my table.
I hope this sounds understandable...
Thanks a lot,
Daniel
View 14 Replies
View Related
Oct 12, 2012
I have a table orders details with a sub form displaying the order, I have a combo box to display the product from products table to place in the sub form products box . I keep getting the error message join key of table details not in record set I have checked my relationships and for keys and there all there .
View 1 Replies
View Related
Jun 11, 2013
I have a main form with combo boxes to filter a subform. I want to be able to export the filtered subform data to a table within the database and only include the filtered dataset not all records.
View 14 Replies
View Related