473,770 Members | 2,028 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Open and update a SQL table

I have a table on a SQL server called history. When I link this table
using an ODBC connection, i give it the username and password and tell
it to save the password and it works great. On my PC. Other computers
however get asked for the password each time they try to write records
to the table.

What I'm trying to do is remove the linked table and open the SQL
database in a module and use the INSERT INTO query to insert my records
and then close the DB connection.

Is this the best way to do this? Can someone provide me some sample
code that will open a SQL database using ODBC and then insert some
records into a history table and then close it all down?

I'm using Access97 and SQL 2000.

Thanks !

Nov 13 '05 #1
7 4596
"Bruce Lawrence" <dg*********@ho tmail.com> wrote in message
news:11******** *************@g 43g2000cwa.goog legroups.com...
I have a table on a SQL server called history. When I link this table
using an ODBC connection, i give it the username and password and tell
it to save the password and it works great. On my PC. Other computers
however get asked for the password each time they try to write records
to the table.

What I'm trying to do is remove the linked table and open the SQL
database in a module and use the INSERT INTO query to insert my records
and then close the DB connection.

Is this the best way to do this? Can someone provide me some sample
code that will open a SQL database using ODBC and then insert some
records into a history table and then close it all down?

I'm using Access97 and SQL 2000.

Thanks !


How is the SQL Server set up? With Windows/Built-in/Integrated security
only or does it allow SQL authentication - and which do you use? It makes
it easier for you if it's Windows authentication only since you don't have
to worry about storing passwords, but if you use SQL authentication what do
you feel about passwords and security? Should people log in each time - or
could a password be stored?
Finally have you considered ADO for this if there is no real need to have
linked tables - just an application which does inserts.

Nov 13 '05 #2
I'm using SQL authentication. The login name is "mplrpt" and there is
no password.
The password could be stored. I'd rather not link the table in Access.
I'd rather open the DB in VB code and insert the records directly.

I'm not sure really about ADO or how it would work in this instance.
All I'm doing now is sifting through sample code in Access and trying
to adjust it to my needs but its not working heh.

Nov 13 '05 #3
"Bruce Lawrence" <dg*********@ho tmail.com> wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.com.. .
I'm using SQL authentication. The login name is "mplrpt" and there is
no password.
The password could be stored. I'd rather not link the table in Access.
I'd rather open the DB in VB code and insert the records directly.

I'm not sure really about ADO or how it would work in this instance.
All I'm doing now is sifting through sample code in Access and trying
to adjust it to my needs but its not working heh.

Well you could try this sort of approach (which uses late binding to avoid
mentioning references)

Private Sub ADO_ADD()

On Error GoTo Err_Handler

Dim cnn As Object
Dim strCnn As String
Dim strSQL As String
Dim lngRecords As Long

strCnn = "Provider=sqlol edb;" & _
"Data Source=MyServer ;" & _
"Initial Catalog=MyDatab ase;" & _
"User ID=mplrpt;Passw ord=;"

Set cnn = CreateObject("A DODB.Connection ")

cnn.ConnectionS tring = strCnn

cnn.Open

strSQL = "INSERT INTO tblTest (MyText, MyNumber) VALUES ('Hello', 22)"

cnn.Execute strSQL, lngRecords

MsgBox lngRecords & " record(s) added", vbInformation

Exit_Handler:

If Not cnn Is Nothing Then
cnn.Close
Set cnn = Nothing
End If

Exit Sub

Err_Handler:
MsgBox Err.Description , vbExclamation, "Error No: " & Err.Number
Resume Exit_Handler

End Sub
Nov 13 '05 #4
Awesome !

Without going into great detail, can you explain the difference between
what you posted and this:

Set mplwksp = CreateWorkspace (blah blah)
Set mplhistory = mplwksp.OpenDat abase (blah blah)

Thank you so much !

Nov 13 '05 #5
Well, slight problem just came up...

When I changed your SQL statement to mine, I get an error

Line1: Incorrect Syntax near ","

This is my statement
SQLstr = "INSERT INTO history
(clockno,job,em pname,ordno,cur date,machno) VALUES" & _
"('" & Packer & "','Packer' ," & packname & "," & order & "," &
Now() & "," & machno & ")"

Nov 13 '05 #6
"Bruce Lawrence" <dg*********@ho tmail.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
Well, slight problem just came up...

When I changed your SQL statement to mine, I get an error

Line1: Incorrect Syntax near ","

This is my statement
SQLstr = "INSERT INTO history
(clockno,job,em pname,ordno,cur date,machno) VALUES" & _
"('" & Packer & "','Packer' ," & packname & "," & order & "," &
Now() & "," & machno & ")"


Do a debug.print SQL and the problem should become clear. It will be quotes
or similar. For the dates use
'2005-12-25' format
Nov 13 '05 #7
Thanks for the reply Justin

The way I fixed it was this:

curdate = Now()

I also made sure my datatype on the SQL server matched the format and
its working great now !

Thanks for all the help. You saved me tons of work

Nov 13 '05 #8

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

Similar topics

2
3872
by: amwi | last post by:
I have tried to solve this on my own for a long time now, so i really need some help here... I use Oracle 10.1 and SQL *plus 10.1. How do i update table a.fkid from table b.pkid with the following "rule". The table b.pkid's should be evenly distributed over table a as fkid's. Does anyone have a tip on how to solve this?
2
8541
by: Mike Leahy | last post by:
Hello all, This question is related to updating tables - is there any way to calculate or update the values in a column in a table to the values in a field produced by a query result? An example of what I'm trying to do is below: update (tbl_ind_mananas LEFT JOIN (select count(*) as count, (dubicacion || zona || manzana) as cod_manzana from tbl_censo_poblacion_1993 group by dubicacion, zona, manzana) tbl1 on relacion = cod_manzana) as...
4
2376
by: dp | last post by:
Anyone have any reason why I can open a table in SQL Enterprise manager, return all rows, and edit the record set, but when I go in through an ADP, connect to the database, and try to edit the same table, it tells me that the table is read only. What gives? There are other tables in this database that I'm able to modify just fine. -B
9
1797
by: baonks | last post by:
hello all here is my problem: I have 2 table 1: K_POS SALDO_A_D SALDO_A_K 11100 105 5 11200 5 105
2
1644
by: Ron | last post by:
Hello, I am trying to do a simple update on employee information. I am a novice at both aspx and SQLServer, so I hope you are not too offended by my code. The following is the update code: --Start of code-- dim objConnection as SqlConnection dim daAddEmp as SqlDataAdapter dim strconnection as string = "myserverlocation"
2
2305
by: Paul712 | last post by:
Recently, I have a table that I use to update a master table. When I run the same Update query that's been successful in the past, most all of the data in the fields in the update fields has been deleted from the update table and nothing is updated in the updated table. Why would this problem start occuring and is there a remedy? thanks!
0
2092
by: jainapurva108 | last post by:
Hi, I have one table with some values as shown in below format... Column-A Column-B Column-C Column-D Column-E 11AA ------ 1234 ------ ASDF------ FIRST ------ONE 22BB ------ 2345 ------ WSDF------ 33CC ------ 3456 ------ YES ------ 44DD ------ 4567------ NO ----- 55EE------ 5678 ------ DUP ------ SECOND -----TWO 66FF------ 6789 ------ OK------
5
5692
by: SQL Learner | last post by:
Hi Alex (Kuznetsov) and All, This is to follow up with my last post, "Link two tables using partial word match". How can I UPDATE table using partial word match? How can I write a SQL statement to do so? (I am using MS-Access.) The two tables and the expected result are listed below: Thank you in advance!
1
2239
by: mrobinsc | last post by:
** This SQL statement returns 4 rows SELECT COUNT(*) G.ACTIVITY_ID G.RESOURCE_TYPE G.RESOURCE_CATEGORY G.RESOURCE_SUB_CAT G.ANALYSIS_TYPE G.PROJECT_ID
1
4063
by: adithi | last post by:
My Table Structure is: Table A Table B Table C colA -PK Col B-PK Col C-PK Col B-FK Col B-FK Col C-FK This relation establish a Concurrent relation where in Cascade Property fails.I can set Cascade property for any two tabnles...but not the third table. My requirement is :
0
9618
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10260
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9906
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8933
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7456
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6712
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.