473,396 Members | 2,033 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Need to populate access table from sql database query

I have an access database with a table that contains two columns:
Computer_Name,User_ID

The table contains 600 computer names. I need to populate the User_ID
column with data from an SQL database.

I want to use VBA to step through each Computer_Name in the table, query
the SQL database for the User_ID associated with Computer_Name, and
populate the User_ID in the access table.

I'm not an Access programmer, but this was thrown at me today. I need
some guidance on how to code this. I have the connection string to the
SQL database working, but I can't figure out how to get the data from
the SQL query into the access table.

Thanks.

*** Sent via Developersdex http://www.developersdex.com ***
Apr 5 '06 #1
4 9539
attach to the SQL database from Access and then just write a query.
When you get what you want, turn the query into an update or append
query.

Apr 5 '06 #2
I got the query side working, but I can't update the access table.
Here's the code:

--------------------------------
Private Sub UpdateUserName(ByVal PCName As String, ByVal UserName As
String)
Dim CurConn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim CurDB As Database

Set CurDB = CurrentDb
Set CurConn = New ADODB.Connection

With CurConn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "data source=" & CurDB.Name
.Open
End With

Set rst = New ADODB.Recordset
rst.CursorType = adOpenDynamic
rst.LockType = adLockOptimistic
rst.Open "SELECT * FROM [Dist 53 3rd party Software] WHERE
[Workstation] = '" & PCName & "'", _
CurConn, , adCmdText

rst!UserID = UserName
rst.Update
rst.Close

End Sub
-------------------------------------

When I run this code, I get: "Current Recordset does not support
updating. This may be a limitation of the Provider, or of the selected
locktype.

Can anyone see what's wrong?

*** Sent via Developersdex http://www.developersdex.com ***
Apr 5 '06 #3
Is there a reason you can't call a function from Access that will
update the fields in question?

UPDATE MyAccessTable
SET MyField = SomeFunction(SomeSQLServerAttachedTable, arg2, arg3)
WHERE SomeField=True;

Apr 6 '06 #4
what happens if you create a link to the SQL Server table from within
Access and then write an update query that updates your Access native
table? This looks like doing everything the hard way. Why not do it
the easy way?

Should be something simple like a simple inner join query and then turn
that into an update query.

UPDATE AccessTable
SET AccessTable.SomeField = SQLServerTable.SomeField
FROM AccessTable INNER JOIN SQLServerTable ON
AccessTable.FieldX=SQLServerTable.FieldY
WHERE...

You shouldn't need any code at all.

Apr 6 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Sean C. | last post by:
Helpful folks, Most of my previous experience with DB2 was on s390 mainframe systems and the optimizer on this platform always seemed very predictable and consistent. Since moving to a WinNT/UDB...
3
by: ssb | last post by:
Hello, This may be very elementary, but, need help because I am new to access programming. (1) Say, I have a column EMPLOYEE_NAME. How do I fetch (maybe, cursor ?) the values one by one and...
19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
0
by: karinski | last post by:
Hi All, I have a split f/e - b/e setup on my database with RWOP queries on the front end. The code below gets a PO number(s), and vendor name from a multi choice list box on another form. It...
3
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems...
52
by: Neil | last post by:
We are running an Access 2000 MDB with a SQL 7 back end. Our network guy is upgrading to Windows Server 2003 and wants to upgrade Office and SQL Server at the same time. We're moving to SQL Server...
13
by: Selesti | last post by:
I have written an Access database that our department uses to store and analyze information on particular jobs. Because our company runs on an enormous SQL DB, I thought it would save some time if...
1
by: jeffro | last post by:
I have a database used for recording survey data. In the database, I have a form that displays a survey participant and a subform that is filled in by selecting a question from a looklist and...
5
by: joshua.nicholes | last post by:
I have an access database that consists of two tables.A data collection table and a species list table. The data collection table has about 1500 records in it and the species list has about 600....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.