help with Beforeupdate [SOLVED]

  • Hi,
    I'm using a userform with several textboxes. I want to check them on userinput.
    When the input is text it must return a msgbox, when it's a value it can go on to the next textbox.
    I'm using the following code to do the checking.

    Private Sub txt1_BeforeUpdate(ByVal Cancel As MSForms.ReturnBoolean)

    If Not IsNumeric(txt1) Then
    MsgBox "test"
    Cancel = True
    Cancel = False
    End If

    But do I have to copy the code for each textbox ie txt1 to txt10 or can I use a loop? Any suggestions are welcom.

    Thanx very much,
    Fluppe :tumble:

  • Hi,
    I have tried to change the code in Andy's example in hope that I could use it, but I didn't manage it.
    Is there maybe someone who can help me working this out or other suggestions?
    Fluppe :(

  • Hi Andy,
    I'm just learning VB since 2 months and I don't understand your code so good.
    I just don't know what I have to change to manipulate the code.
    I just tried to change a few words but I actually don't understand what I'm doing.

    I want to use the beforeupdate function for a few textboxes on a userform.
    When a user enters text instead of a value it must return a msgbox.
    Maybe you can give me a tip?

    Tanx Abdy :yes:

  • Hi Fluppe,

    I managed to modify this in my tea break :D

    It doesn't display a msgbox because the user can not type a non numeric value.

    See attached.

    Any questions post back.



  • Hi Andy,

    Thank you very much for answering my question instead of enjoying your tea break. :D

    Maybe someday I can help you,...

    I think I do understand a little more.
    Just one little question:
    What does the 46 stands for?
    vbKey0 To vbKey9, 46
    I thought I had to acces the ascii tabel by entering a decimal or hexadecimal number?
    So ie. number1 = decimal 49 or hexadecimal 31 ? Am I wrong?

    Fluppe :thumbcoo:

  • Hi Fluppe,

    The 46 is the ascii value for '.' (period) or the decimal point in values.

    You may have to change that if you use ',' comma for the decimal point. The value is 44.

    You can use the functions ASC(".") to get the value of a character or CHR(44) to get the character of a value.

    Keep scanning this forum and your understanding will grow.

    Cheers :beergrin:


Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!