关于错误处理 [英] On error handling

查看:80
本文介绍了关于错误处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我有一个主要的Case表单,当我点击一个按钮时,会打开一个新的客户表单。在客户端表单上,我有3个文本框,供用户用来创建新客户端,名字,姓氏和出生日期。我还有两个名为客户名称和ID的隐形文本框,由于我遇到的一个问题,我最终创建了该文本框。所有文本框都是从Clients表绑定的,客户端名称只是第一个和最后一个连接的。然后我有一个添加新客户端按钮。在客户端表上,ID是主键,并且在将客户端添加到表之前,所有必需的索引都是第一个,最后一个和dob字段,并且索引为唯一字段。


我想要的是,在填写第一个,最后一个和dob文本框之后,当我单击Add New按钮时,从条目自动化的客户端ID以及连接的客户端名称将填充到Main表单中,客户表单关闭。


如果他们没有填写所有3个字段,则会显示一条消息,指出所有三个字段都是必需的。然后他们必须输入信息并再试一次。然后,如果他们输入所有三个字段,如果所有三个字段都不唯一,则会显示一条消息,指出客户端已存在。然后,他们应该能够查看同一表单上的列表框并选择客户端。


我在处理错误时遇到问题。我尝试了不同的方法,没有任何作用。我最接近的是获取状态客户端的消息,但表单已关闭,因此他们无法访问列表框。到目前为止,这是我的代码,没有错误处理。

Hello,

I have a main Case form, that when I click a button, a new Client form opens. On the Client form, I have 3 text boxes that users use to create a new client, first name, last name, and date of birth. I also have 2 invisible text boxes named Client name and ID that I ended up creating due to one of the problems I am encountering. All text boxes are bound from the Clients table, and the client name is just the first and last concatenated. I then have an Add New Client button. On the Clients table, the ID is the primary key and the first, last, and dob fields are all required and indexed to all be unique before the client is added to the table.

What I want, is for after the first, last, and dob text boxes are filled out, when I click Add New button, the client ID that was automated from the entry as well as the concatenated client name are populated into the Main form and the Client form closes.

If they didn''t fill out all 3 fields, then a message states that all three fields are required. They then have to enter the information and try again. Then, if they enter all three fields, if all three are not unique, a message states that the client already exists. They should then be able to look at the listbox that is on the same form and choose the client.

I am having trouble with the error handling. I have tried different ways and nothing works. The closest I came to was getting the message to state client exists but the form closed so they couldn''t access the listbox then. Here is my code so far with no error handling.

展开 | 选择 | Wrap | 行号

推荐答案

MysticElaine,


看起来好像是你的。 ..然后语句可能与您想要做的事情有点不同步。如果没有任何文本框是空的(First If ... Then的条件),则不需要第二个If ... Then。

MysticElaine,

It looks as if your If ... Then Statements might be a bit out of sync with what you want to do. If none of the Text Boxes are Null (conditions of the First If...Then), there is no need for the second If...Then.

展开 | 选择 | Wrap | 行号


您好,感谢您的回复。是的,我会喜欢一些额外的帮助。我是Access和编码的新手,因此我一直在教自己。就目前而言,如果用户输入相同的信息,则客户端表单将关闭并填充主Case表单的客户端ID和客户端字段。但是,会给出一个新的客户端ID,这是不好的,因为客户端已经存在且具有不同的ID号。这是我遇到麻烦的地方。我以为我可以添加一个错误处理程序,但所做的只是提供客户端已经存在的消息,并且仍然关闭了客户端表单并填充了Case表单。所以我想也许我需要把DoCmd.Close移到其他地方,但我不知道在哪里。


现在,我有一个案例与案例相关联的表单表。我还有一个客户端与客户链接的表单表。在案例表单上,他们单击一个新的条目按钮,该按钮可以提取客户端表单。用户应首先搜索客户端,并在添加新客户端(表单右侧)之前从列表框中选择是否存在(表单的左侧)。我确实做到这一点,以便他们必须在其中一个搜索框中键入内容才能添加任何人,但这并不意味着他们不会只输入一个字母,然后尝试添加客户端。对于客户表格,我有名字,姓氏和DOB。字段可见,并且在添加到Clients表之前都被编入索引。我还有客户端ID,它是主键,客户端名称和客户端名称。字段不可见,以便在添加新的唯一客户端时,这些字段将填充到案例表单的客户端ID中。和客户关闭客户表格中的字段。


很抱歉这么啰嗦并感谢您的帮助。


编辑:我可以吗
Hi, thank you for the response. Yes, I would love some additional assistance. I am very new to Access and coding so have been teaching myself as I go along. As it stands right now, if a user enters identical information, the Client form closes and populates the Client ID and Client fields of the main Case form. However, a new Client ID is given, which is bad since the client already exists and has a different ID number. This is where I am having trouble. I thought I could add an Error handler, but all that did was give the message that the client already exists and still closed the Client form and populated the Case form. So I thought maybe I needed to move the DoCmd.Close somewhere else, but I didn''t know where.

Right now, I have a "Case" form that is linked with the "Cases" table. I also have a "Client" form that is linked with the "Clients" table. On the Case form, they click a New Entry button that pulls up the Client form. The user is supposed to search first for the client and choose from the listbox if they exist (left side of the form) before adding a new client (right side of form). I did make it so that they had to type something in one of the search boxes before being able to add anyone, but that doesn''t mean they won''t just type one letter and then try to add the client.

For the Client form, I have the "First Name", "Last Name", and "DOB" fields visible and are all indexed to be unique before being added to the Clients table. I also have the "Client ID", which is the primary key, and "Client Name" fields invisible so that when a new unique client is added, those fields are populated into the Case form''s "Client ID" and "Client" fields upon the Client form closing.

Sorry for being so long-winded and thanks for the help.

Can I do
展开 | 选择 | Wrap | 行号


好的。很多事情发生了!让我们一次尝试这一步。


首先要做的事情:尽管两个名字相同且姓名极差的人也很少见DOB ,这有点无关紧要。我强烈建议您在客户端表中为所有客户端提供唯一标识符。毕竟,有人可能正在寻找John Smith,04年8月14日。并且真正意味着John Smyth 04 Aug 04。尝试找到另一种方法来识别您的客户。然后,当您选择客户端时,它始终基于ClientID(即使查找客户端的条件基于名称和DOB)。


其次,如果您需要用户在可以进入新客户端之前查找客户端,然后以这种方式构建表单。您可以使用未绑定的文本框控件来执行此操作,其中用户输入数据(甚至是部分数据),db将查找符合这些条件的记录。您的用户永远不应该意外如果你不想要它们就创建一个记录,这就是为什么你想出新的客户ID。


我知道你问了很多,我不是在给很多,但我保证,如果我们逐一完成这项工作,我们最终会到达那里。


你想要解决的第一步是什么,因为现在,它好像有一个帖子太多了。


我来这里是为了hepp!


: - )
OK. A lot going on! Let''s try to take this one step at a time.

First things first: Although it is EXTREMELY rare that two people with the same First and Last Names also have the same DOB, that is kinda immaterial. I would highly recommend that in your Clients Table that there simply be a unique identifier for all clients. After all, someone could be looking for "John Smith, 14 Aug 04" and really mean "John Smyth 14 Aug 04". Try to find another way to identify your clients. Then, when you select a client, it is always based on the ClientID (even though the criteria for looking for the Client is based on name and DOB).

Second, if you want the User to look for a client before they can enter a new client, then build your form that way. You can do this by using unbound text box controls in which the user enters data (even partial data) and the db will look for records that match those criteria. Your users should never "accidentally" create a record if you don''t want them to, which is why you are coming up with new client IDs.

I know you are asking a lot, and I am not giving a lot, but I promise you, if we work through this piece by piece, we will eventually get there.

What is the first step you want to tackle, because right now, it seems like there is too much for one post.

I''m here to hepp!

:-)


这篇关于关于错误处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆