Solved

Append field to database during run-time

Posted on 2001-06-20
5
172 Views
Last Modified: 2010-05-02
I am very new to VB and I am trying to append a new field to a database with the name of the field being a string the user enters in (boolean-type field) and I am getting stuck.  I am trying not to use SQL statements or adodb connections because I don't really understand them. I tried:

 MattressType.Recordset.Fields.Append txtHardness.Text

but it gives me a run-time error of "type mismatch" and highlights the "txtHardness.Text" which is a string but I think I'm supposed to have an object there. Please help me as I am very confused (as you can probably tell).
Thanks!
~Sarah
0
Comment
Question by:snaegs99
5 Comments
 
LVL 5

Expert Comment

by:rkot2000
ID: 6211389
Append does not append a field to the database, it allows to build a dynamic recordset.
If you want to change/alter a table you need to use tsql ? for sqlserver or sqlplus for oracle.
0
 
LVL 3

Accepted Solution

by:
jrspano earned 50 total points
ID: 6211455
for sql server 7 and 2000

alter table tablename ADD columnname FLOAT NOT NULL

this adds a column named columnname that has float for type and doesn't accept nulls.
0
 
LVL 3

Expert Comment

by:jrspano
ID: 6211458
you really should learn to understand ado.  there is only so much you can do without them.
0
 
LVL 3

Expert Comment

by:Hornet241
ID: 6211766
If you want to append a field you must use the TableDef object and append a field object, using ADO and SQL would be much easier and more worth your while to learn for many other reasons.

But here is a sample I used to use with VB3, DAO and Access 2.0

    Dim db as Database
    Dim tb As New TableDef
    ReDim fd(0 To 6) As New Field

    Set db = CreateDatabase(DBName$, DB_LANG_GENERAL)
    tb.Name = "language"

    fd(0).Name = "text"
    fd(0).Type = db_text
    fd(0).Size = 255

    tb.fields.append fd(0)

    db.tabledefs.append tb

hope this helps
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7139597
Hi snaegs99@devx,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will suggest to:

    Accept jrspano's comment(s) as an answer.

snaegs99@devx, if you think your question was not answered at all or if you need help, you can simply post a new comment here.  Community Support moderators will follow up.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question