473,386 Members | 1,602 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,386 software developers and data experts.

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 4567
"Bruce Lawrence" <dg*********@hotmail.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.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*********@hotmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.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=sqloledb;" & _
"Data Source=MyServer;" & _
"Initial Catalog=MyDatabase;" & _
"User ID=mplrpt;Password=;"

Set cnn = CreateObject("ADODB.Connection")

cnn.ConnectionString = 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.OpenDatabase (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,empname,ordno,curdate,machno) VALUES" & _
"('" & Packer & "','Packer'," & packname & "," & order & "," &
Now() & "," & machno & ")"

Nov 13 '05 #6
"Bruce Lawrence" <dg*********@hotmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.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,empname,ordno,curdate,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
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...
2
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...
4
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...
9
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
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: ...
2
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...
0
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 ------ ...
5
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...
1
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
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 ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.