How to save an untouched new record - ms-access-2010

after reading a lot in this forum (and also in others), I still haven't found a solution for my problem. It's a classical scenario : a Customer creates an Order, which in turn has OrderItems.
So my tables are as follow :
tbl_Customer
cust_Id as Long (primary key, autoincrement)
cust_Name as String
cust_Adress as String
cust_Phone as String
etc
tbl_Order
ord_Id as Long (primary key, autoincrement)
ord_CustId as Long (references as foreign key field cust_Id in table tbl_Customer)
ord_Date as Date
tbl_OrderItem
oi_OrdId as Long (references as foreign key field ord_Id in table tbl_Order)
oi_ArtId as Long (references as foreign key field art_Id in table tbl_Article which is not relevant in this scenario)
oi_Count as Integer (quantity of article(s))
oi_Price as Double (price of article)
As you can see it is a not so complicated m:n relationship between customers and articles which are ordered.
Beside these tables I created in Access a form frmCustomer (based on tbl_Customer) which owns a subform frmOrder (based on tbl_Order). These two forms are connected by fields cust_Id and ord_CustId.
SubForm frmOrder in turn has a subForm frmOrderItem (based on table tbl_OrderItem). They are connected by fields ord_Id and oi_OrdId.
Some example data inserted in these tables are shown correct. Switching customers results in showing its orrders and orderitems. So far so good.
Now I want to insert a new order, and adding some orderitems to it.
If I click on button "New empty record" (record-navigation pane) of subForm frmOrder, a new empty order-record is created with empty fields and empty subform orderitem.
When I now insert a new orderitem and try to store it, an error message appears, saying the record cannot be stored because field oi_OrdId cannot be null.
That's true, because the order-record is not yet stored, and hence autoincremented field ord_Id is not yet filled. Only if I edit a field in the until now untouched order-record (for example orderdate) and leave that field, the record is stored, and the field ord_Id is filled, and also field oi_OrdId in form frmOrderItem.
But, because the fields ord_CustId (=[Forms]![frmCustomer]![cust_Id], value copied from parent form frmCustomer) and ord_Date ( =Date() ) have default-values, I don't want to edit a field first.
I would like to enter immediatly orderitems.
Is there an event (-procedure) I can use to save the untouched order-record (how ?) automatically, when I enter a field of subform frmOrderItem ?
Or has somebody of the community a helpful solution ?
And by the way, is there a way to access a new, not yet saved record ?
Thank you very much in advance for your help
ulofb

Now I want to insert a new order, and adding some orderitems to it. If
I click on button "New empty record" (record-navigation pane) of
subForm frmOrder
Don't. Do it the other way round. Block record inserts in the subform for a new order record. After insert/save of the order form, enable record inserts in the subform.

Related

Database design for unknown fields

I am trying to make form builder in android. I have a real problem at designing database. In this application User first drags the required fields to the screen and change the labels of fields. The fields Contains:
CheckBox
RadioButton
TeXtBox
PlainText
This is my mockup:
I have real problem in designing database.I need a help to accomplish it.
Any Links to the tutorials or ER Diagrams will be really appreciated.
In this application user will drag his required fields to the screen as shown in mock up. Suppose when user drags on checkbox icon then the Editable Checkbox label and editable options will appear in the screen. Then Form builder names the label according to his requirements and options also. In this way he first builds the form .
That's what I created in 10 minutes, hope it helps.
TB_FieldType //field type
UUID_Type,
Type_Name, (Checkbox, RadioButton, Textbox, PlainText, Password, DropdownSelect...)
TB_FieldRule //Table field rule
UUID_Rule,
Rule (numeric only, not null...)
TB_UserTable //Save user designed thrir own table
UUID_Table,
Table_Name, (Designed table name)
TB_UserTable_Field //Designed table field detail
UUID_TableField,
UUID_Table,
UUID_Type,
UUID_GroupID, (can be null if field is single type*)
UUID_Rule,
Field_Name, (Display name)
Field_Length,
TB_Group //(for field(s) in multi type*, like RadioButton, DropwodnSelect... )
UUID,
GroupID,
GroupData,
I would create a table for storing the field definitions with fields like this:
survey_id (reference to the survey which the field belongs to)
field_id (unique id of the field)
field_type (checkbox, radio, plain etc.)
field_label
field_data (additional information if required, e.g. selection options for radio - dependent on type)
field_index (defines the order of fields)
... any additional field you may need
From this data, you can dynamically build your GUI.
And you will need another table for storing the answers (if it is in scope of your app):
field_id (reference to the former table)
value (entered by the user)
...user_id, timestamp etc. according to your needs

MS CRM 2013 Process Update Account - multiple values to one field

I'm trying to implement an update procedure like the one in this blog post (via extra entity and workflow updating account, triggered when the new entity is being created)
http://www.powerobjects.com/2013/08/01/updating-records-in-microsoft-dynamics-crm/
In my list and the new entity "Account Update" I have 3 fields for the full name of a company (name, name_2, name_3).
In my workflow I want to put these 3 together and combine their values in the Account field "Company" (the company's name).
In the process I tried to insert them via the "Form Assistant" and in the field "Company" I now have the following entry:
{Name(Account Update);Name_2(Account Update);Name_3(Account Update)}
but it doesn't seem to work. After my import and update of the account (which ends successful) the value in "Company" is only the value of the first name field.
Is it possible to combine values?
What exactly does it do, when I choose more than one field in the Form Assistant and say OK?
So at last I figured out how to archive it.
With the "Form Assistant" you can combine or add multiple field values to one new field but it is a bit tricky.
The value in the process update the properies have to look like this:
{Name(Account Update)} {Name_2(Account Update)} {Name_3(Account Update)}
BUT
It does not work if you enter this as text, you have to add the fields one after another so that they are recognized as fields (and marked yellow).
Click into the field (here: "Company").
Then choose the first field in the Form Assistant. Click "Add", choose it in the list below and click "OK". Now the field is in the field "Company".
Now go behind the end of the text in the field make a space and then choose and add the second field (clear the list in the Form Assistant before so that now only the second field is in the list)
So it's right if it looks like:
{Name(Account Update)} {Name_2(Account Update)}
Wrong if looks like following (happens when you keep the first field in the list before adding the second with "OK")
{Name(Account Update);Name_2(Account Update)}

Synchronization between AOT and DB - Will I lose data?

I am new to AX 2009. I am adding a new field to the Tax 1099 tab for vendors to store additional info. I created a new extended type that is a 9 char. string. When I create a new string field on the VendTable the default length is 10. I then change it to use my extended type (9 chars in length). When I try to save the changes I get the text that says "...could result in data truncation". I know that is fine because this is a new field and there is no data in the db yet.
BUT - I also get the message "The action you have taken will drop and re-create the table VENDTABLE and all associated index. This can be caused by renaming a field or changing the type and/or size of the field."
It's unclear to me if it is ok for me to continue. If I continue will I loose all the data in my VENDTABLE or will the data be re-created along with the table?
I've read the information here but I'm still unsure if I will loose my VENDTABLE data or not if I continue.
The system will create a new table with the new field size, copy all the data from vendtable to the new table (truncating data in your 1099 field), then delete vendtable and rename the new table to vendtable.

Store Timestamp in GridView

I have a table with three columns that I need to display on a ASP.NET page. (SQL Server 2005, ASP.NET 2.0)
id int
value varchar(50)
tstamp timestamp
I use the timestamp field to handle concurrency validation so it's for internal use only and will never be displayed to the end user. But I need to store it somewhere in order to do proper updates.
Here's my update sproc.
UPDATE ValueTable SET value = #value
WHERE (id = #id) AND (tstamp = #tstamp)
SELECT #tstamp=tstamp FROM ValueTable
WHERE id=#id
I use a SqlDataSource to connect to my database and the schema has all three columns. My grid view will only display two fields since the timestamp field is hidden (Visible=False)
When I profile my asp page it looks like it doesn't store the timestamp anywhere even though I have a "hidden" field in the table.
How would you store a timestamp value in general on a web page? It should never be displayed, but it is needed for any updates.
After a lot of playing around I think I found a half-decent solution.
The problem seems to be that fields that are "Visible=false" are not included or bound in any update or delete commands.
The HiddenField works fine for Update commands, so if you are not doing any Delete commands you should be fine by including a hidden field which is bound (Bind(TStamp)) to the timestamp column in a templated field.
The problem is that if you are doing Deletes as well it doesn't look at any bound, hidden fields.
What I came up with was to add the timestamp to the data keys of the grid view. That way it will be considered a composite key together with the ID.
So, in short, add the timestamp to the DataKeyNames of the GridView/DetailsView etc, and remove any visible fields. That seemed to do the trick.

Coding practice: how to avoid hard coding?

I have a table in the database that store 4 category and the structure of the table is ID (GUID), description. I load the category into a dropdown list (asp.net webform) to allow people to select a category and based on what they selected. I'll then display info associated with their selection and hide the others.
Currently, i do a "select case" based on the GUID that i hard coded in code behind to display the associated info. Is there a better way to do this without hard code in GUID on the code behind?
What is the Data that's associated with the Guid/Description...
The data you've hardcoded sound's like a candidate for being added to the database itself.
If it's one piece of information per Category/Guid, then consider extending your Database Table to store that info to.
If it's multiple piece of information per Category/Guid, then consider creating a new Table With a CategoryID on it, and a foreign key relationship between your Category Table and your ExtraInfo table
You could query the database for the GUIDs when the app starts and cache them in a static Dictionary.
you could store the GUID in your web-config and load it at run time. then, you can easily replace that GUID with another w/o having to recompile.
You should have a Categories table and a Posts table (or whatever it is that you will tag with your categories). In the Posts table you have a column for the CategoryID (assuming each post can only belong to one category), so that you only have the category name in one place (normalize your data).
When you render the dropdownlist, you select the GUID:s from the database. No hard coding, and if you add another category (or remove one) the dropdownlist will automatically reflect the available categories.
If you bind the dropdown list to the Category row or a Tuple that contains the category name and the value you can load the Guid in your codebehind using the SelectedValue property. You will then set the DataTextField and DataValueField on the Dropdownlist.

Resources