Page 1 of 1 1
Topic Options
#130008 - 2004-11-22 01:47 PM Add field to mdb - table
Steven Offline
Lurker

Registered: 2004-11-22
Posts: 1
I want to add fields to my software table if the field doesn't exist already. But I don't find how I can do this action. Could someone please help me? This is my script:

Code:
 

$Connection = CreateObject("ADODB.Connection")
$Connection.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=c:\inventory\inventory.mdb"
$Connection.Open()
if not @error
$Command = CreateObject("ADODB.Command")
$Command.ActiveConnection = $Connection
$Recordset = CreateObject("ADODB.Recordset")
$Recordset.CursorType = 3
$Recordset.LockType = 3
$Recordset.ActiveCommand = $Command

$Command.CommandText = "SELECT * FROM [tbl_Software] WHERE SerialNumber='$SerNo'"
$Recordset.Open($Command)
$Recordset.Fields("SerialNumber").Value = $SerNo
$Recordset.Update
$Recordset.Close()

$Connection.Close()
$Connection = 0
$Recordset = 0
$Command = 0
endif



Edited by Steven (2004-11-22 01:50 PM)

Top
#130009 - 2004-11-22 04:22 PM Re: Add field to mdb - table
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Here is half your answer, how to add a new column:

$= $Connection.Execute("ALTER TABLE Table1 Add SerialNumber VarChar(40);")

Thinking about the best way to detect whether the column is missing though ... anybody ?

Top
#130010 - 2004-11-22 05:45 PM Re: Add field to mdb - table
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
This may help: TableInfo() function

Ref: http://www.microsoft.com/office/community/en-us/default.mspx?dg=microsoft.public.access.queries&mid=53c7e3b9-af02-4e92-8413-034b1332cf8b
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#130011 - 2004-11-23 02:47 AM Re: Add field to mdb - table
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
See also the DB...() UDFs, e.g. DBCommand().
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1782 anonymous users online.
Newest Members
ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder, M_Moore
17887 Registered Users

Generated in 0.077 seconds in which 0.043 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org