What I need to do is change the datatype in my table from text to date/time programatically. I have to run this several times a day so I am writing a macro to do it for me.
Thanks for all your help!!!
2 1193
I got it figured out. -
Option Compare Database
-
'The AlterFieldType Sub procedure requires three string parameters with an
-
'optional fourth. The first string specifies the name of the table
-
'that contains the field to be changed. The second string specifies the
-
'name of the field to be changed. The third is the data type of the field.
-
'The fourth and optional parameter holds the size value when you specify
-
'binary data types and text data types.
-
-
Sub AlterFieldType(TblName As String, FieldName As String, DataType As _
-
String, Optional Size As Variant)
-
Dim cd
-
If IsMissing(Size) Then
-
DoCmd.RunSQL "ALTER TABLE [" & TblName & "] ALTER COLUMN [" & FieldName & _
-
"] " & DataType
-
Else
-
DoCmd.RunSQL "ALTER TABLE [" & TblName & "] ALTER COLUMN [" & FieldName & _
-
"] " & DataType & "(" & Size & ")"
-
End If
-
End Sub
-
-
-
Public Function Update_GKNStatus()
-
DoCmd.SetWarnings False
-
Screen.MousePointer = 11
-
-
DoCmd.OpenQuery "qry-getdates"
-
AlterFieldType "getdates", "Line Unit 0001", "date"
-
AlterFieldType "getdates", "line unit 9997", "date"
-
AlterFieldType "getdates", "Line Unit 0002", "date"
-
AlterFieldType "getdates", "line unit 9998", "date"
-
AlterFieldType "getdates", "Line Unit 0003", "date"
-
AlterFieldType "getdates", "Line Unit 0004", "date"
-
AlterFieldType "getdates", "Line Unit 9901", "date"
-
AlterFieldType "getdates", "Line Unit 0005", "date"
-
AlterFieldType "getdates", "Line Unit 0006", "date"
-
AlterFieldType "getdates", "Line Unit 0007", "date"
-
AlterFieldType "getdates", "Line Unit 0008", "date"
-
AlterFieldType "getdates", "Line Unit 0009", "date"
-
AlterFieldType "getdates", "Line Unit 0010", "date"
-
-
DoCmd.SetWarnings True
-
Screen.MousePointer = 1
-
-
End Function
-
Glad you got it working and thanks for posting the working code!
Regards,
Scott
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jon Brunson |
last post by:
Is it possible to use a DataAdapter to fill a DataTable, change the
DataColumns of that DataTable (and maybe even it's name) and then commit
those changes to the database (in my case SQL Server...
|
by: iporter |
last post by:
Hi - I am changing a field from type nvarchar to type text, given that
I need to store strings longer than 255 characters. To do this I
change the data type in SQL Server, then I change the...
|
by: Greg Scharlemann |
last post by:
Given some recent success on a simple form validation (mainly due to
the kind folks in this forum), I've tried to tackle something a bit
more difficult. I'm pulling data down from a database and...
|
by: Peter |
last post by:
Can anyone tell me how to change the data type of a field in a table created
with a make table query? The field is a binary and must be changed to text.
alternately does anyone know how to specify...
|
by: Dan |
last post by:
Could someone please help me with auto importing a series of data
files into an Access table. I tried to follow code given below in a
previous messagebut i'm getting error messages.
Here's my...
|
by: windandwaves |
last post by:
Hi Gurus
I have a module with a bunch of functions that tell me everything about a
table (e.g. the number of children, whether it exists, the table
description, etc..., data-entry quality,...
|
by: Larry Bird |
last post by:
I've created a AlertDataClass below within the class I have tables and column that I've create. In the AlertDataAccess class I'm trying to insert data into my tables. AlertDataAccess is a Module...
|
by: rbinington |
last post by:
Hi,
I am trying to write a DNN module that has the ability to insert articles into an article repository. I want the users to be able to move pages around and enter text into the FCKEditor. I...
|
by: James Mills |
last post by:
On Thu, Oct 9, 2008 at 2:26 PM, Warren DeLano <warren@delsci.comwrote:
Yes it does :)
I second this.
It's far better to use Data Structures
rather than Programming Constructs
|
by: Mubs |
last post by:
Hi ppl,
I am trying to insert records into my database using a form. this works. but after this i would like the records to be displayed onto another page.. the database gets updated but the...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |