Solved

Append field to database during run-time

Posted on 2001-06-20
5
169 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now