As a relative beginner with Access/VBA (2003 version), I am looking for a solution to what seems to be a fairly simple problem...
When a user inputs a text string in a form object, I would like that string to become a new value in a table which already consists of a variety of fields and records. I don't want a new RECORD to be created, but would like to place this new value (as entered by the user) in any particular box I choose in the table.
For example, if field number 2 in my table has three values listed in its column in the records below, and field number 3 has 10 values in its column, I might want to add the user-entered text string as the fourth value in column 2, without appending an entire new record to the bottom of the table.
Help or guidance on this is appreciated...
Anthony
11 5762 MMcCarthy 14,534
Recognized Expert Moderator MVP
On your form you have a textbox in which the user enters data. Do you also have a field on the form that corresponds to the field on the table that you want this data to go to?
Is your form bound to this table. i.e. Is the Record Souce of your form based on this table?
NeoPa 32,556
Recognized Expert Moderator MVP
If you're talking about dynamically adding fields to a table definition on the fly within a form, then perhaps you don't appreciate how easy (possible) this isn't.
Assuming I understand you correctly, then don't even go there in Access. It won't be worth your pain (assuming it's even possible).
MMcCarthy 14,534
Recognized Expert Moderator MVP
If you're talking about dynamically adding fields to a table definition on the fly within a form, then perhaps you don't appreciate how easy (possible) this isn't.
Assuming I understand you correctly, then don't even go there in Access. It won't be worth your pain (assuming it's even possible).
It's possible to add a field using vba but for obvious reasons its fraught with danger. If you add a field to a table then where is that field used and/or referenced. What implications does it have throughout the database? The rule on something like this is don't do it unless you've explored all other ways of solving your problem.
If like NeoPa says this is what you are trying to do the WHY? There may be a better way.
Thanks for the replies. I will try to explain my purpose and perhaps there is a simpler way to achieve what I want to do…
The tables that I want to place values in (see previous post) are not tables set up for the purpose of listing “records” in. I am simply using the tables as store-houses of lists for combo-boxes.
There are probably as many as 50 or 60 different unique lists (found under fields in a selection of tables) which may appear as choices for a particular combo-box on my form depending on choices made in other combo-boxes. I am just using the fields in these tables as a convenient way of being able to view and edit my various lists that can appear as choices in a combo-box (because there are so many lists).
So these tables that I want to alter values in are not meant to contain “records” as such, rather lists for combo-boxes for the user to make a choice from. The actual choice made by the user from a combo-box IS stored as a proper record in another table.
What I really want to do is allow a user to ADD a unique choice for a particular combo-box by typing in a new string which could then be added as a new value under a field on one of those “store-house” tables therefore permanently added to the list of choices for that combo-box.
Have I confused anyone yet?!? Any thoughts on how this might be possible or should I try a different technique?
Anthony
NeoPa 32,556
Recognized Expert Moderator MVP
I confess to being a little confused still, even though you have explained it quite well.
Do you have a separate table for each List / Combo-Box?
If so, why do you say you are not adding a record?
You mention fields, but this is where I come a little unstuck, surely each List / Combo-Box has a fixed number of fields...
MMcCarthy 14,534
Recognized Expert Moderator MVP
Hi NeoPa
I think the problem is the old communication one again. Maybe we should post a sticky as to what is a field, record, control, etc.
Anyway,
To add a record to any table you can use the following (adding a value to a lookup list IS adding a record to a table).
For this example, I am naming my table Lookup_Value and the fields are an ID (Autonumber) field which gets populated automatically and a field called sValue. The textbox on the form that the user enters the value into is txtNewValue. -
-
Dim strSQL As String
-
-
strSQL="INSERT INTO Lookup_Value (sValue) VALUES ('" & Me.txtNewValue & "');"
-
DoCmd.RunSQL
-
-
Me.lstBoxName.Requery ' This will requery the listbox with the new value
-
-
Can I try a different tack with this problem? Here are two columns in my table:
(Field 1) CARDIOVASCULAR
Atrial Fibrillation
Myocardial Infarction
Acute pulmonary oedema
xxxx
(Field 2) RESPIRATORY
Pneumonia
Pneumothorax
Pleural Effusion
Haemothorax
Respiratory Failure
Pulmonary Embolus
If I want to change the value xxxx under field " CARDIOVASCULAR" I can use the following VBA code which works well. "NewValue" is a value entered by a user in a text box. -
Dim dbs As Database
-
-
Set dbs = CurrentDb
-
-
dbs.Execute "UPDATE Table_Complications " _
-
& "SET Cardiovascular = 'NewValue' " _
-
& "WHERE Cardiovascular = ‘xxxx’;"
-
-
dbs.Close
-
If, however, 'xxxx' is actually an empty cell (like the ones below it) but I want to put "NewValue" in that spot, I don't know how to do it from VBA ... I have tried the following which doesn't seem to work: -
Dim dbs As Database
-
-
Set dbs = CurrentDb
-
-
dbs.Execute "UPDATE Table_Complications " _
-
& "SET Cardiovascular = 'NewValue' " _
-
& "WHERE Cardiovascular = Null;"
-
-
dbs.Close
-
-
End Sub
-
And I have tried variations such as ... - & WHERE IsEmpty(Cardiovascular) = True;"
But I can't seem to get the table to alter at all with these experiments.
Is there a selection of code which can add my user's new string to the bottom of the Cardiovascular list in an empty cell (without adding a new record to the table as such)?
NeoPa 32,556
Recognized Expert Moderator MVP
Unless I misunderstand badly (I've done it before), the data structure here is quite wrong.
Let me explain.
It seems you have a table 'Table_Complications' which has two separate fields in it 'Cardiovascular' & 'Respiratory'.
It appears that you're storing disparate values in the same record - 'Atrial Fibrilation' in the same record as 'Pneumonia'.
These are not logically connected, so should not be stored together.
Can you please confirm I'm reading this correctly here?
MMcCarthy 14,534
Recognized Expert Moderator MVP
I agree with NeoPa that your structure is incorrect. However, if you use the below code it should update ALL empty fields to the new value. -
Dim dbs As Database
-
-
Set dbs = CurrentDb
-
-
dbs.Execute "UPDATE Table_Complications " _
-
& "SET Cardiovascular = 'NewValue' " _
-
& "WHERE Cardiovascular = '" & "" & "';"
-
-
dbs.Close
-
-
I have tried a different approach to my problem which includes changing my data structure somewhat and have found a solution which works.
Thanks for the help and advice.
Anthony
MMcCarthy 14,534
Recognized Expert Moderator MVP
I have tried a different approach to my problem which includes changing my data structure somewhat and have found a solution which works.
Thanks for the help and advice.
Anthony
You're welcome. Please repost if you have any further problems.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Reply Via Newsgroup |
last post by:
Folks,
Say I have a table, ten columns, ten rows - Each with a word in it. I want
to change the values of some/all of the cells in the table via a hyperlink.
How do I reference each cell and...
|
by: Galina |
last post by:
Hello
I have an application in MS Access 2000. I have a form, which includes
a subform. The subform is based on a table, but locked for any
editing. There is Edit button. When clicked, it starts a...
|
by: Andrew |
last post by:
I use conditional compiler constants, set through the VBA IDE in
Tools, <projectname> Properties, that I refer to throughout my code to
control which code is used during development, and which...
|
by: N. Graves |
last post by:
Hello... thank you for your time.
I have a form that has a List box of equipotent records and a sub form
that will show the data of the equipment select from the list box.
Is it possible to...
|
by: F. Michael Miller |
last post by:
I have a db with Access front end, sql back, linked tables. I need to be
able to change input masks at the table level in code.
Any ideas?
Thanks!
|
by: nyt |
last post by:
I have a problem of number and text field.
I got the database file(mdb) that contains many combo boxes used and
its list values are created by "value list"
For eg field
Field name= 'furniture'...
|
by: Ecohouse |
last post by:
I have a main form with two subforms. The first subform has the child
link to the main form identity key.
subform1 - Master Field: SK
Child Field: TrainingMasterSK
The second subform has a...
|
by: Simon |
last post by:
Dear reader,
The syntax for the VBA code to change the RecordSource of a Master Report
is:
Me.RecordSource = "TableOrQueryName"
|
by: sillyr |
last post by:
Hi- I'm using Access 2007. I wanted to change a default value for a field that previously had no default value. I though it would be easy- just set the default value setting to the number t hat I...
|
by: thatcollegeguy |
last post by:
Below are my 3php and 2js files.
I create a table using ajax/php and then want to change the values in the tables add(+ number for teamid) id's for each specific td in the table. I don't know...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |