473,385 Members | 1,531 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Create and update a table from a

9
Hi All,

INTRODUCTION
I have been following this post:

"Checkbox form to allow user to select query output fields"

(BIG THANKS TO ADezii AND ALL THE OTHER CONTRIBUTORS)

In a nut shell,
1. A user selects check boxes for the criteria he/she wants to see,
2. Using a combo box, they can choose the particular brand/family of products they want to see the above selected criteria for:

Expand|Select|Wrap|Line Numbers
  1.  strSQL_2 = "SELECT " & _
  2.    Left$(strSQL, Len(strSQL) - 2) & _
  3.    " FROM Products " & _
  4.     "WHERE ([Family] Like [Forms]![MAC]![Combo99]);" 
3. The VBA creates a query based on the brand/family and check box criteria.

WHAT I HAVE MANGED
I have managed to create the "dynamic query" based on my check boxes and have also manged to keep changing the WHERE criteria using combo boxes.

THE PROBLEM
I now want a method of adding more records to the query. In this case, based on the same criteria but for a different brand/family.

Hence finally, a record set with selected criteria (filed headings) about several brands. All this effort is for a dynamic database & a user friendly interface.

NOTES
1) I believe you can only append records to a table and not to a query. I tried to create a "make table query", and then use an append query to append records. However I couldn't create the VBA to create a "make table query" in the first instance. The next challenge would have been to make a "dynamic append query".

2) The "dynamic query" will change several times in a single use of the database depending on what the user wants to achieve. The data will then be used to create a report/exported to [Some Application]. I believe the table can be deleted and re-created each time the "dynamic query" fields are modified (using the check box controls).

3) I don't have much experience with coding.

Thank you in advance. :)
Sep 26 '13 #1
12 1823
hb001
9
Hi All,

Funnily enough, I managed to solve part of the problem shorty after posting (Thanks zmbd for the edit).

I simply changed the where code to:

Expand|Select|Wrap|Line Numbers
  1. "WHERE ([Family] Like [Forms]![MAC]![Combo99]
  2.  OR [Family] Like [Forms]![MAC]![Combo113]);"
I am now faced with the next challenge, how do I move this query into a table without having it link to the original table. It's like a static table which can be deleted and re-created each time a new "dynamic query" is created?

Cheers
Sep 26 '13 #2
zmbd
5,501 Expert Mod 4TB
HBB01:

I'm not really following what you are trying to do here.
You shouldn't normally be creating and deleting tables in a well designed database.
The queries can be saved or created on the fly depending on what you are trying to do. The stored queries are held in the QueryDef Object (DAO) Office 2010 and these can be altered on the fly - this is something I used to do for a report.
What I do now, is create one parameter query based on the entire recordset, build my report, and open the report by passing either a filter or parameters.
Use parameters in queries and reports I've found this to much cleaner, easier to maintain, and more stable.
Sep 26 '13 #3
hb001
9
Hi zmbd,

Thank you for your response.

I shall have a read through the links you have sent me and see if I can work something out.

I shall post back if I find a solution or get stuck.

Thanks.
Sep 27 '13 #4
hb001
9
I have had a look,

I cannot seem to see how these will help me achieve my goal (maybe I missed something).

I will attempt to explain why I want to create the table and hopefully this will help find a way forward:

Please see the attached file for a preview of my form. I can get the query to work with the two sets and get the data to one query.
Sample data:
(Brand) Apple
(Family) iPhone, MacBook, iPad etc.
(Model) 4S/5/5S, Air, Retina etc.

I am now worried because (realistically) a user could want up to 10-20 sets (maybe even more) with the same query fields.

My idea was to use the form to construct the query design,then make it create a table and finally use another query to update this table.

This would mean I only need 1 set of combo boxes that can add an infinite number of records to the table.

I hope this makes sense.

Thank you.


Attached Images
File Type: jpg Form.jpg (27.2 KB, 534 views)
Sep 27 '13 #5
zmbd
5,501 Expert Mod 4TB
Queries are not tables.
Queries pull information from tables.
Queries can take actions on tables.
Queries can either be stored in the database, in form control, VBA code, or built as a string in VBA code

The example you started with (ADezii Code) does this last action, building the code. Once the code is built you can store the code by adding it to the collection (not normally done - but whatever).

SO how can we use this information to help solve your question? This will depend on your database design. We'll need to see a list of your tables, their fields, and any relationships between the fields/tables. Something like this:

table1
[field_1] PK - autonumber
[field_2] text(25)

table2
[field_A] PK - autonumber
[field_B](FK 1:M with table1![field_1])

From here we maybe able to help.

If the database is normalized, then what I suspect we'll do is use your comboboxes to find the "set" by a unique primary key. We can then add this to the query string and then requery the form based on the new string. Depending on the form, we might even be able to do this using the form's filter.
Sep 27 '13 #6
hb001
9
Thank you for your response and apologies for the delay.

I have only one table that pertains to the data I am working on. There is another, but the tables are not related (so I have not included it?)

The main table has about 106 fields, so I am using the main ones. (ok?)

Products
[Field_1] Database ID - autonumber
[Filed_2] Brand - Text
[Filed_3] Family - Text
{Filed_4] Model - Text
...

Hope this helps.

Thank you.
Sep 30 '13 #7
hb001
9
Expand|Select|Wrap|Line Numbers
  1. strSQL_2 = "SELECT " & Left$(strSQL, Len(strSQL) - 
  2. 2) & " FROM Products " & "WHERE ([Database ID] = [Forms]!
  3. [MAC]![Combo125]
  4.  OR [Database ID] = [Forms]![MAC]![Combo128] 
  5. OR [Database ID] = [Forms]![MAC]![Combo129] 
  6. OR [Database ID] = [Forms]![MAC]![Combo130] 
  7. OR [Database ID] = [Forms]![MAC]![Combo131]);"
That pulls the information for many records together but it requires multiple combo boxes. I would like to have one combo box with an "add to comparison" button.

Thanks.
Sep 30 '13 #8
zmbd
5,501 Expert Mod 4TB
(...)The main table has about 106 fields(...)
It so sounds like the database isn't normalized.

Hmmm....
combobox
rowsource = select the table that has the fields of interest
rowsource type = "field list"

The combobox will now show the field names in the dropdown list. The name of the selected field would be combobox.value which can be appended to a string.

Your next thing will be to get the comparison value for the field - this may not be so simple unless you have a list of values somewhere in the db.

Anyway say in the first combobox your client has selected combobox.value="brand" then your next combobox would then need to have its rowsouce filtered down to the brands in your database. I'm guessing that these brands are in one of the 106 fields of your table - yes?! You could then use a command button to add the string "[Brand]= 'selected'" to your WHERE clause.

I think that this is really clunky, and will lead to some really awful field names that will violate the restricted tokens list. Making your report is going to be a real nightmare as you have no set field structure

I really think you need to Normalize your database.
To use your example:
You could have a table: (Brand) Apple
You could have a table: (Family) iPhone, MacBook, iPad etc.
You could have a table :(Model) 4S/5/5S, Air, Retina etc.
Then you then might have a related table that has the details...
table
tbl_specs
[specs_pk] autnumber
[specs_fk_brand] numeric long fk 1:m w/brand
[specs_fk_family] numeric long fk 1:m w/family
[specs_fk_model] numeric long fk 1:m w/model
[specs_memory]
[specs_height]
[specs_length]
[specs_(....other information....)]

Now the customer would select from three comboboxs that are linked to your three tables (Brand)(Family)(Model) the comboboxes could be cascaded as in this example ([*]Cascaded Form Filtering) from there you would be able to pull the [specs_pk] and add it to an SQL using the IN() function within the WHERE clause.
Once the customer is happy, they could then press the compare button and the database would pull up the report.
Sep 30 '13 #9
hb001
9
Thank you for your response zmbd. I really appreciate your effort.

In theory I think I can follow what you mean. But when it come's to writing the code, I quite frankly do not have the knowledge of VBA to write it up.

In terms of normalisation I think it is a good idea too, but I think at this point it would be best for Version 2.0

As of now, I have modified the design of the form and I no longer use the 3 combo box "filters", but rather a single combo box with 4 columns to easily identify the product.

My understanding from what I have done and the suggestions you have made is now that (correct me if I am wrong):
I can store all the [Database ID]'s as a single string variable (they are all numeric though) which is created/added together when the "add to comparison" button is clicked, then set the following:

Expand|Select|Wrap|Line Numbers
  1. .... "WHERE ([Database ID] = [MyString]);"
Is this correct? If so how can I do this?

I can foresee the same problem with the reports, but this is a big, specific and ambitious project and I have no shortage of motivation to see it 100% complete. :)

Thank you.
Sep 30 '13 #10
zmbd
5,501 Expert Mod 4TB
you'll build your string just as you've shown in the first post's code block by appending to the where clause using "&" and then you will append that string to the SQL.

Frankly, I've been normalizing databases for so long, it will take me awhile to figure out the mishmash you are trying to do. ADezii is most likely a little quicker on the code.

Honestly, the effort you are making here would be better spent normalizing the database and creating it properly. V2.0 is "too" late. Quantity vs. Quality is what gets programers in trouble.
Oct 1 '13 #11
hb001
9
Thanks for your response.

By V2.0, I meant I will build this database up get it working perfectly and then start again from scratch, so my V2.0 is the users V1.0.
This (maybe) is strange but it's what works best for me...

For the minute though I will try and resolve this mishmash (new word for me) by creating a string variable, then calling it in the where statement following your advise.

Thanks.
Oct 1 '13 #12
hb001
9
Hi all,

So this is what I have manged

Expand|Select|Wrap|Line Numbers
  1. 'Dynamic WHERE
  2. For Each ctl In Me.Controls
  3.     If ctl.ControlType = acComboBox Then
  4.         If ctl.Value Then
  5.             strWHERE_D = strWHERE_D & "[Database ID] 
  6. = " & "[Forms]![MAC]!" & 
  7. "[" & ctl.Name & "]" & " OR "
  8.             End If
  9.         End If
  10.     Next
  11.  
  12. 'Create the WHERE criteria
  13. strWHERE = strWHERE_D & "[Database ID] = 1"
  14.  
  15. 'Build complete SQL Statement
  16. strSQL_2 = "SELECT " & Left$(strSQL, 
  17. Len(strSQL) - 2) & " FROM Products WHERE " 
  18. & strWHERE & ";"
It uses about 20 combo boxes with 4 columns each. It does the job & I am quite happy with it. But it still lacks the ability to do an infinite number of comparisons. I would really like to know how to do that.

Cheers!
Oct 1 '13 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: amwi | last post by:
I have tried to solve this on my own for a long time now, so i really need some help here... I use Oracle 10.1 and SQL *plus 10.1. How do i update table a.fkid from table b.pkid with the...
2
by: Mike Leahy | last post by:
Hello all, This question is related to updating tables - is there any way to calculate or update the values in a column in a table to the values in a field produced by a query result? An...
1
by: poohnie08 | last post by:
i have a excel spreadsheet showing staff name, date,work hour, ot hour, slot1, slot2, slot3, slot4 and others). The "()" will keep repeating from day 1 until end of month. eg in excel spreadsheet,...
2
by: DaveDiego | last post by:
I'm building a report that has a count of cases for employees. I have separate queries that count, OpenCases, NewCases, TotalCases, Etc. I would like to put all those counts into a record for each...
2
by: Paul712 | last post by:
Recently, I have a table that I use to update a master table. When I run the same Update query that's been successful in the past, most all of the data in the fields in the update fields has been...
3
by: Rahul B | last post by:
Hi, I have a user UCLDEV1 which is a part of staff and a group(db2schemagrp1) to which i have not given any permissions. The authorizations of that user are shown as db2 =get authorizations...
1
by: mrobinsc | last post by:
** This SQL statement returns 4 rows SELECT COUNT(*) G.ACTIVITY_ID G.RESOURCE_TYPE G.RESOURCE_CATEGORY G.RESOURCE_SUB_CAT G.ANALYSIS_TYPE G.PROJECT_ID
1
by: adithi | last post by:
My Table Structure is: Table A Table B Table C colA -PK Col B-PK Col C-PK Col B-FK ...
7
by: Jarosław Kozik | last post by:
how to create script - update database development code using MSSQL 2000 Enterprise Manager i'm trying in this way all tasks -genetate sql script .... ( in this way I can generate only CREATE...
5
by: Mr Key | last post by:
Hi all! Once again I have found myself in position of asking for your assistance! Your hints,Contributions or Creations has been very usefully for access users around the world! I have a query...
1
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...
0
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.