Thanks Paul. That fixes it. Is there an easy explanation as to why it needed the ' deliminaters?
On Tuesday, December 22, 2020, 01:32:06 PM CST, Paul Baldy <pbaldy@gmail.com> wrote:
The value needs delimiters. Try
CurrentDb.Execute "UPDATE " & TableToModify & " SET " & NewColName & " = '" & myString & "'"
Paul
------ Original Message ------
From: "Sean Cooper via groups.io" <smcjb=yahoo.com@groups.io>
Sent: 12/22/2020 11:17:14 AM
Subject: [MSAccessProfessionals] UPDATE TABLE issue
The following works finePublic Sub MyAddColumn()Dim TableToModify As StringDim NewColName As StringDim mylong As LongTableToModify = "ABC"NewColName = "NewCol20"mylong = 1122CurrentDb.Execute "ALTER TABLE " & TableToModify & " ADD COLUMN " & NewColName & " Long"CurrentDb.Execute "UPDATE " & TableToModify & " SET " & NewColName & " = " & mylongEnd SubBut when I try and modify it to update with a string or text instead of a Long I get a Run-Time error 3061, Too few parameters. Expected 1. I've tried changing the ALTER TABLE to CHAR(14), Dim'ing the String with no size all with no luck.Public Sub MyAddColumn()Dim TableToModify As StringDim NewColName As StringDim myString As String * 14TableToModify = "ABC"NewColName = "NewCol20"myString = "ABCD1234567890CurrentDb.Execute "ALTER TABLE " & TableToModify & " ADD COLUMN " & NewColName & " TEXT(14)"CurrentDb.Execute "UPDATE " & TableToModify & " SET " & NewColName & " = " & myStringEnd SubAny help appreciated.ThanksSean
Tidak ada komentar:
Posting Komentar