简体   繁体   中英

How do I set up a MS Access form to create a new row in table and set one field as a default value?

So I am not positive I am even asking the correct question, but here it goes. I currently have a MS Access Form built so that someone can enter in a new work order. You are able to set the company, the part number wanted, quantity, and the Work Order number is an auto generated value that I use for my primary key. All of that works great and successfully adds a new row to the table "Work Orders". However, when this form is used to create a new work order I want the last field in the table "Work Orders" which is called "Status" to be set to "Not Started".

I successfully made an update query that asks for the Work Order Number, and will set the "Status" field to "Not Started". Here is the code for that:

UPDATE 03A_WorkOrderList 
SET 03A_WorkOrderList.Status = "Not Started"
WHERE ((([03A_WorkOrderList].WO_Num)=[WO_Num:]));

If you give the update query work order number everything works great and the "Status" field is updated.

So back to the form I decided to attach the update query to the build event where the update happens after the new line is created. That seems to have worked too except it asks for the work order number. I totally understand why because it is the code that is in the update query of: WHERE ((([03A_WorkOrderList].WO_Num)=[WO_Num:]));

What I cannot figure out is how to have it pull the work order number that was automatically generated and use that for the update query.

If I am going about this all wrong, please let me know. TIA.

In Ms Access, open your [Work order] table in design mode. Select the Status field and in the property section below, you can set the Default value to be Not started . This way you don't need to perform an update and all new orders will automatically have Not started status.

or in your add order form, On before update event, you can set the status = 'Not started'

I was able to get the functionality that I was looking for with the following UPDATE Query:

UPDATE 03A_WorkOrderList SET 03A_WorkOrderList.Status = "Not Started"
WHERE [03A_WorkOrderList].WO_Num=(SELECT MAX(WO_Num) FROM 03A_WorkOrderList);

Since the WO_Num is auto generated and I want to edit the very same one I was working on, I could just look for the MAX(WO_Num). I then made this UPDATE query apart of the build event of the order form.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM