excel 2003 database fields - is it possible to change the name - excel

I am using excel 2003 query to pull information from databases and fields, I would like to rename the field headers but every time I refresh the data it defaults back to the original example
the field name is stit_ref which I want to change to req reference; if I do a refresh it just goes back to stit_ref after editing the cell/refreshing.
Is there a way to keep the edited field names. I attempted to do it via Microsoft Query by editing the Column heading but I get a syntax error.

In MS Query you can write custom query and use aliases for selected fields:
SELECT stit_ref AS [req reference] FROM table

In the query definition it should say something like:
SELECT -other fields go here-,stit_ref FROM TableName
change that to:
SELECT -other fields go here-,stit_ref As [req referenc] FROM TableName

Related

Table with variable number of rows in MS Office mail merge [duplicate]

I'm creating a compliance mailing for my organization, the mailing will include merge fields that identify the office location, physician, and SiteId. The mailing will also include a table of information that is dependent upon the particular SiteId.
I'd like to use the import table function of MS word and set up a query that references a merged field (SiteId) so that the inserted tables populate the appropriate data for the particular site. I'm unable to do this.
How can I set up this document so that I can import only records from my source (an ms access query) that match the SiteId merge field?
Word's mail merge does not support one-to-many relationships. There are ways to coerce it, but only one of them can yield a table as a result and over the years it has become less and less reliable as Microsoft has not regarded it as important enough to maintain...
What you need to do is set up a query that provides ONLY the information you want displayed in the table, plus the key (SiteId). It's best to sort it so that all the SiteId entries list together, and are in the order the data will come through in the mail merge data source.
On the Insert tab go to Text/Quick Parts/Insert Field and select the Database field from the list in the dialog box. Click "Insert Database" and follow the instructions in the dialog box to link in the data. Be sure to set the Query Options to filter on the first SiteId from the data source. When you "Insert Data" make sure to choose the option to "Insert as a field".
This inserts a DATABASE field in the document which you can see by toggling field codes (Alt+F9). The field code can be edited and what you need to do is substitute the literal SiteId value you entered for the query with its corresponding MergeField.
When you execute the merge to a new document that should generate a table for each data record corresponding to the SiteId for the record. But, as I said, Microsoft hasn't done a great job of maintaining this, so it may require quite a bit of tweaking and experimenting.
If the results are not satisfactory then you should give up the idea of mail merge and use automation code to generate and populate the documents.
You can find more (albeit somewhat out-dated) information on this topic at http://homepage.swissonline.ch/cindymeister/mergfaq1.htm

Data Parameter in Excel not working with Access Query Connection

I have a connection to an Access DB query within Excel. The field in the Access query is an expression turning a field into a proper date. The problem that I'm having in Excel lies within passing the parameter from a cell containing the date that I want the query to run for. The results are either completely wrong or result in nothing. I have tried modifying the parameter cell to just about everything to no avail. I have tried the edit query option under view connection and when prompted to put in the value for the parameter, it actually returns the data I want. I would thing that this would be exactly the same parameter it would be grabbing from the formatted cell?
I have attached my connection's SQL command text below. And also an image with more detail and screenshots.
This is the command text from Excel containing my Where clause:
SELECT Query1.SETYPE, Query1.`SEORD#`, Query1.ORBILL, Query1.ORCUST, Query1.ORLDAT,
Query1.ORCONS, Query1.SESEV, Query1.CMTYPE, Query1.CMTEXT, Query1.ORDDATfix
FROM `C:\USERS\DRED\DESKTOP\ServiceFailures.accdb`.Query1 Query1
WHERE Query1.ORDDATfix =?
SELECT Query1.SETYPE, Query1.`SEORD#`, Query1.ORBILL, Query1.ORCUST, Query1.ORLDAT, Query1.ORCONS, Query1.SESEV, Query1.CMTYPE, Query1.CMTEXT, Query1.ORDDATfix
FROM `C:\USERS\DRED\DESKTOP\ServiceFailures.accdb`.Query1 Query1
WHERE (Query1.ORDDATfix>=?)
Apparently putting the clause in parenthesis fixed the problem.

Microsoft Access 2013 Record Source Columns

I recently got tasked with customizing a report in an access database, I havent touched access in years so its a little rusty for me. I have successfully added the Fields to the table, added them to the form and added them to the report. If i run the report they query correctly. But all the other fields on the report are setup with an expression such as:
=IIF([Mold Temp High]=0,"----",[Mold Temp High])
Now the expression makes 100% to me but when it auto populates the field, such as Mold Temp High, for all the previous fields i can see they show up as Record Source Column fields, but for any new field i have added shows up as a Text Box.
If i create an expression with the new fields i get a Circular Reference and it shows #type on the report instead of the value.
Just curious to why the new fields show up as TextBoxs and not Record Sources.
I'm guessing that you are dragging the new fields from the field list. When you do this, it creates the text box with the exact same name as the data field. So when you use this name in an expression, it thinks you are referencing the text box object. To prevent this problem, make sure that every time you create a new textbox (or any control) from a data field that you name it something different by setting the Name property of the text box. Generally I just add "txt" to the front of the field name. This will ensure that you are always explicitly referring to either the textbox name or the data field name.
What if you change your logic around a bit..
We remember, IIF is constructed as:
=IIF((Some_Table_Field or value),True-condition,False-condtion)
You maybe looking at:
=IIF([Mold Temp High]=NULL,"----",[Mold Temp High])
Or, maybe (use ISNULL or ISBLANK it has been a while for Access with me as well):
=IIF(isnull([Mold Temp High]),"----",[Mold Temp High])
Or, rather:
=IIF([Mold Temp High]<1,"----",[Mold Temp High])
Hope this makes sense.

Updating a table Access and Excel VBA

I have one table called: Transaction. This table has the following fields: (ID,ProductName,Amount,Date) placed in an excel sheet that is connected with MS Access database. ID is the only unique field. Sometimes, my user submits a transaction that has let's say 5 records. Then, they want to modify the submitted data in case if they entered incorrect amount and they want to correct it. I want to write a code in VBA that will do the update. my current query is:
Update table Transaction(ProductName,Amount) set ProductName=#Product,Amount=#Amount)
where Date=#date;
This query does not work fine because obviously it replaces all the records data with the data of the last resubmitted record because my condition is weak. My difficulty is that I can't find a good condition in the where clause that will do the update a record by record accordingly.
Please help,
You will need to use the unique id of the record, in your case the ID field to guarantee you are updating the correct record.
Something like the following:
Update table Transaction(ProductName,Amount) set ProductName=#Product,Amount=#Amount) where ID = "id of record you want to update"
Enjoy!

Excel: Use a cell value as a parameter for a SQL query

I'm using MS Excel to get data from a MySQL database through ODBC.
I successfully get data using an SQL query. But now I want that query to be parameterized.
So I wonder If it is possible to use a cell value (a spreadsheet cell) as a parameter for such a query.
For example, for this query:
select name from user where id=1
I'd like to get the id value from, say, cell D4 in the spreadsheet.
Is that the proper approach to parameterize a query? and how can I do it?
Thanks.
I had the same problem as you, Noboby can understand me, But I solved it in this way.
SELECT NAME, TELEFONE, DATA
FROM [sheet1$a1:q633]
WHERE NAME IN (SELECT * FROM [sheet2$a1:a2])
you need insert a parameter in other sheet, the SQL will consider that information like as
database, then you can select the information and compare them into parameter you like.
If you are using microsoft query, you can add "?" to your query...
select name from user where id= ?
that will popup a small window asking for the cell/data/etc when you go back to excel.
In the popup window, you can also select "always use this cell as a parameter" eliminating the need to define that cell every time you refresh your data. This is the easiest option.
queryString = "SELECT name FROM user WHERE id=" & Worksheets("Sheet1").Range("D4").Value
The SQL is somewhat like the syntax of MS SQL.
SELECT * FROM [table$] WHERE *;
It is important that the table name is ended with a $ sign and the whole thing is put into brackets. As conditions you can use any value, but so far Excel didn't allow me to use what I call "SQL Apostrophes" (ยด), so a column title in one word is recommended.
If you have users listed in a table called "Users", and the id is in a column titled "id" and the name in a column titled "Name", your query will look like this:
SELECT Name FROM [Users$] WHERE id = 1;
Hope this helps.

Resources