|
-
Oct 30th, 2006, 05:31 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] Help with MS Access Query String
hi guyz,
pls does anybody know why this gives error
Code:
ALTER TABLE tblDVD CHANGE 'DVD_Name' 'DVD_Title' TEXT
I'm working with MS ACCESS
Last edited by modpluz; Oct 30th, 2006 at 05:48 PM.
-
Oct 30th, 2006, 09:48 PM
#2
Re: Help with MS Access Query String
Change is probably your issue here.
See the syntax definition for ALTER TABLE in Access -
http://office.microsoft.com/assistan...&respos=1&rt=6
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 31st, 2006, 09:29 PM
#3
Thread Starter
Fanatic Member
Re: Help with MS Access Query String
yeah i've seen that but its not helping me.
ok let me come out clean...
how do i change the name of a particular column in a table, in an MS ACCESS Database?
-
Oct 31st, 2006, 09:40 PM
#4
Re: Help with MS Access Query String
Just specify the Column attribute property you need.
VB Code:
ALTER TABLE tblDVD ALTER COLUMN DVD_Name TEXT(25)
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 31st, 2006, 10:04 PM
#5
Thread Starter
Fanatic Member
Re: Help with MS Access Query String
 Originally Posted by RobDog888
Just specify the Column attribute property you need.
the column attribute i need is the name property
VB Code:
ALTER TABLE tblDVD ALTER COLUMN DVD_Name TEXT(25)
from what i can see above, there is no place to specify new column name
thanks
-
Nov 1st, 2006, 01:47 AM
#6
Re: Help with MS Access Query String
I doubt you can change the field name in access, instead i do this way to change the field name, add a new temp field transfer the old field values to the temp and drop the old field create a new field as you wish and then transfer the values from your temp field to this field...
VB Code:
ALTER TABLE tblDVD Add TempField TEXT(25)
Update Table tblDVD Set TempField=DVD_Name
Alter Table tblDVD Drop Column DVD_Name
Alter Table tblDVD Add NewFieldName VarChar(25) Null 'Access accepts varchar in sql
Update Table tblDVD Set NewFieldName=TempField
Alter Table Drop Column TempField
If an answer to your question has been helpful, then please, Rate it!
Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.
-
Nov 2nd, 2006, 10:53 PM
#7
Thread Starter
Fanatic Member
Re: Help with MS Access Query String
 Originally Posted by ganeshmoorthy
I doubt you can change the field name in access, instead i do this way to change the field name, add a new temp field transfer the old field values to the temp and drop the old field create a new field as you wish and then transfer the values from your temp field to this field...
VB Code:
ALTER TABLE tblDVD Add TempField TEXT(25)
Update Table tblDVD Set TempField=DVD_Name
Alter Table tblDVD Drop Column DVD_Name
Alter Table tblDVD Add NewFieldName VarChar(25) Null 'Access accepts varchar in sql
Update Table tblDVD Set NewFieldName=TempField
Alter Table Drop Column TempField
i really appreciate your help but the code is not working
it bumped into an error on getting to
Code:
Update Table tblDVD Set TempField=DVD_Name
here is what i did...
VB Code:
'i created a sub function of my own
'the id_col helps in knowing what Record ID is
Sub changeFldName(old_name As String, new_name As String, _
id_col As String, table_name As String)
Dim rsFld As ADODB.Recordset, _
sSQL As String, _
rcd_cnt As Long, r_i As Long
On Error Resume Next
Set rsFld = New ADODB.Recordset
'pls note that the function [B]Connect[/B] is a function that initiates the connection
If cn.State = adStateClosed Then Call Connect
sSQL = "ALTER TABLE " & table_name & " ADD " & new_name & " TEXT"
cn.Execute (sSQL)
sSQL = "SELECT * FROM " & table_name
rsFld.CursorType = 2
rsFld.Open sSQL, cn
rcd_cnt = rsFld.RecordCount
For r_i = 1 To rcd_cnt
sSQL = "UPDATE " & table_name & " SET " & new_name & "=" & old_name & _
" WHERE " & id_col & "=" & rsFld(id_col)
cn.Execute (sSQL)
rsFld.MoveNext
Next r_i
rsFld.Close
Set rsFld = Nothing
sSQL = "ALTER TABLE " & table_name & " DROP " & old_name
cn.Execute (sSQL)
End Sub
and you call it like this...
VB Code:
Call changeFldName("DVD_Name", "NewFieldName", "DVD_ID", "tblDVD")
and here is the Connect Function
VB Code:
Function Connect()
On Error Resume Next
If cn.State = adStateClosed Then
cn.CursorLocation = adUseClient
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data " & _
"Source="some_db_file.mdb;Persist Security Info=False;" & _
"Jet OLEDB:Database Password=password"
End If
End Function
Last edited by modpluz; Nov 2nd, 2006 at 11:08 PM.
-
Nov 2nd, 2006, 11:12 PM
#8
Thread Starter
Fanatic Member
Re: Help with MS Access Query String
 Originally Posted by danasegarane
try this,
VB Code:
sSQL = "UPDATE Table " & table_name & " SET " & new_name & "=" & old_name & _
" WHERE " & id_col & "=" & rsFld(id_col
you mind explaining what you're trying to do with your code above(because its an extract from what i posted earlier) or maybe perhaps you're refering to someone else
Last edited by modpluz; Nov 4th, 2006 at 02:33 PM.
-
Nov 2nd, 2006, 11:20 PM
#9
Re: Help with MS Access Query String
Sorry Yar,
I think i have misread the post.Any way wht is the error messge you are gettign?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|