Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Append field to database during run-time

Posted on 2001-06-20
5
Medium Priority
?
176 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 150 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses

660 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