If语句的问题 [英] Problems with an If statement

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

问题描述

我试图在表单上为数字框写一个if语句。我想设置它,这样你只能在框中输入一定数量的字符。例如,您无法输入任何多于或少于5个数字。如果你这样做,你会收到一个错误。我写的代码是半工作的任何建议都会大大放弃。


我把它放在onEnter

Im trying to write an if statement for a number box on my form. I want to set it so you can only enter in a set number of characters in the box. For example you cant enter any more or less than 5 numbers. If you do you get an error. The code that I wrote is half working any suggestions would be greatly apperciated.

I put this in the onEnter

展开 | 选择 | Wrap | 行号

推荐答案

输入控件时会触发 OnEnter 事件,这使得此任务不适合。此代码将执行您想要的验证:
The OnEnter event fires when you enter the control, which makes it inappropriate for this task. This code will do the validation you want:
展开 | 选择 | Wrap | 行号


您也可以将框中的输入掩码设置为 00000" ;.然后在表单的错误处理程序中...

You could also just set the input mask on the box to "00000". Then in the error handler for the form...

展开 | 选择 | Wrap | 行号


谢谢你的misslinq和zepphead,


我现在已经绞尽脑汁待了2天。我会设置掩码类型,这将更容易,如zepphead所述,但问题是我使用的版本是一个准系统版本,所以我甚至不能使用掩码类型,这是真正限制我能做的事情。但是从好的方面来说,我还是要学习更多我想要学习的代码。


我将框重置为文本框而不是数字框。意识到以后我无法作为数字字段输入起始零。 (您可能会认为他们会在将来的更新或版本的Access中更改它)。我插入(linqs)代码并且效果很好:D非常感谢你的帮助。我确实知道我可以更改字段大小,将其限制为仅输入5个字符,但我想确保您不能输入少于5个字符,这是代码所做的。很好,非常感谢你。


只是想知道是否有任何类型的书或非常详细的网站,我可以读到所有这些工作如何,你们中的任何一个会推荐?或者你只需​​要从其他人那里学习它并试错?
Thank you both missinglinq and zepphead,

I have been racking my brain over this for 2 days now. I would set the mask type which would be way easier as mentioned by zepphead but the problem is the version I am using is a barebones version so i can not even use the mask type at the moment which is really limiting things I can do. But on the upside I get to learn a lot more code which I want to learn anyway.

I reset the box to a text box instead of a number box. Realized that later on I could not enter in starting zeros as a number field. (You would think they would change that in future updates or versions of Access). I plugged in (linqs) code and it works great :D thank you so much for the help. I did figure out that I could change the field size limiting it to only 5 characters to be entered but I want to make sure that you can not enter in less than 5 as well, which the code does. Very nice thank you so much.

Just wondering is there any kind of book or very detailed site where I can read up on how all of this works more that either of you would recommend?? Or do you just have to learn it all from other people and trial and error??


这篇关于If语句的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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