Results 1 to 9 of 9

Thread: [RESOLVED] Help with MS Access Query String

  1. #1

    Thread Starter
    Fanatic Member modpluz's Avatar
    Join Date
    Sep 2005
    Location
    Lag, NG
    Posts
    633

    Resolved [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.
    If you want the rabbit to hop, move the carrot - Paul Kellerman(Prison Break)

    onError GoTo http://vbforums.com



    My Bits:
    VB6: Change Column Name in MS ACCESS

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  3. #3

    Thread Starter
    Fanatic Member modpluz's Avatar
    Join Date
    Sep 2005
    Location
    Lag, NG
    Posts
    633

    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?
    If you want the rabbit to hop, move the carrot - Paul Kellerman(Prison Break)

    onError GoTo http://vbforums.com



    My Bits:
    VB6: Change Column Name in MS ACCESS

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Help with MS Access Query String

    Just specify the Column attribute property you need.
    VB Code:
    1. 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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  5. #5

    Thread Starter
    Fanatic Member modpluz's Avatar
    Join Date
    Sep 2005
    Location
    Lag, NG
    Posts
    633

    Re: Help with MS Access Query String

    Quote Originally Posted by RobDog888
    Just specify the Column attribute property you need.
    the column attribute i need is the name property
    VB Code:
    1. 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
    If you want the rabbit to hop, move the carrot - Paul Kellerman(Prison Break)

    onError GoTo http://vbforums.com



    My Bits:
    VB6: Change Column Name in MS ACCESS

  6. #6
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    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:
    1. ALTER TABLE tblDVD Add TempField TEXT(25)
    2. Update Table tblDVD Set TempField=DVD_Name
    3. Alter Table tblDVD Drop Column DVD_Name
    4. Alter Table tblDVD Add NewFieldName VarChar(25) Null 'Access accepts varchar in sql
    5. Update Table tblDVD Set NewFieldName=TempField
    6. 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.


  7. #7

    Thread Starter
    Fanatic Member modpluz's Avatar
    Join Date
    Sep 2005
    Location
    Lag, NG
    Posts
    633

    Re: Help with MS Access Query String

    Quote 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:
    1. ALTER TABLE tblDVD Add TempField TEXT(25)
    2. Update Table tblDVD Set TempField=DVD_Name
    3. Alter Table tblDVD Drop Column DVD_Name
    4. Alter Table tblDVD Add NewFieldName VarChar(25) Null 'Access accepts varchar in sql
    5. Update Table tblDVD Set NewFieldName=TempField
    6. 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:
    1. 'i created a sub function of my own
    2. 'the id_col helps in knowing what Record ID is
    3. Sub changeFldName(old_name As String, new_name As String, _
    4.                     id_col As String, table_name As String)
    5.  Dim rsFld As ADODB.Recordset, _
    6.  sSQL As String, _
    7.  rcd_cnt As Long, r_i As Long
    8.  
    9. On Error Resume Next
    10.  
    11.  Set rsFld = New ADODB.Recordset
    12. 'pls note that the function [B]Connect[/B] is a function that initiates the connection
    13.  If cn.State = adStateClosed Then Call Connect
    14.  
    15.  sSQL = "ALTER TABLE " & table_name & " ADD " & new_name & " TEXT"
    16.  cn.Execute (sSQL)
    17.  
    18.  
    19.  sSQL = "SELECT * FROM " & table_name
    20.  rsFld.CursorType = 2
    21.  rsFld.Open sSQL, cn
    22.  rcd_cnt = rsFld.RecordCount
    23.  For r_i = 1 To rcd_cnt
    24.   sSQL = "UPDATE " & table_name & " SET " & new_name & "=" & old_name & _
    25.             " WHERE " & id_col & "=" & rsFld(id_col)
    26.   cn.Execute (sSQL)
    27.   rsFld.MoveNext
    28.  Next r_i
    29.   rsFld.Close
    30.   Set rsFld = Nothing
    31.  
    32.  sSQL = "ALTER TABLE " & table_name & " DROP " & old_name
    33.  cn.Execute (sSQL)
    34. End Sub
    and you call it like this...
    VB Code:
    1. Call changeFldName("DVD_Name", "NewFieldName", "DVD_ID", "tblDVD")

    and here is the Connect Function
    VB Code:
    1. Function Connect()
    2. On Error Resume Next
    3.  
    4. If cn.State = adStateClosed Then
    5.     cn.CursorLocation = adUseClient
    6.     cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data " & _
    7.                 "Source="some_db_file.mdb;Persist Security Info=False;" & _
    8.                 "Jet OLEDB:Database Password=password"
    9. End If
    10.  
    11. End Function
    Last edited by modpluz; Nov 2nd, 2006 at 11:08 PM.
    If you want the rabbit to hop, move the carrot - Paul Kellerman(Prison Break)

    onError GoTo http://vbforums.com



    My Bits:
    VB6: Change Column Name in MS ACCESS

  8. #8

    Thread Starter
    Fanatic Member modpluz's Avatar
    Join Date
    Sep 2005
    Location
    Lag, NG
    Posts
    633

    Re: Help with MS Access Query String

    Quote Originally Posted by danasegarane
    try this,
    VB Code:
    1. sSQL = "UPDATE Table " & table_name & " SET " & new_name & "=" & old_name & _
    2.             " 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.
    If you want the rabbit to hop, move the carrot - Paul Kellerman(Prison Break)

    onError GoTo http://vbforums.com



    My Bits:
    VB6: Change Column Name in MS ACCESS

  9. #9
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    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
  •  



Click Here to Expand Forum to Full Width