Results 1 to 8 of 8
  1. #1
    amd711 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Oct 2012
    Posts
    28

    Just numeric input for all textboxes in the form

    I have a form for data input with more than 200 textboxes, almost all of them are numeric

    i usually use the following code to allow only for numbers input in a textbox

    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
        If KeyAscii < Asc("0") Or KeyAscii > Asc("9") Then
            KeyAscii = 0
        End If
    
    End Sub
    is it possible to apply this code for all of the textboxes so that i dont have to do it 200 times

  2. #2
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,001
    If you put your code in a Function, you'd still need one line of code, in the KeyPress event of each Control, to call it, and since your current code could be reduced to one line, what would be the point?
    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
      If KeyAscii < Asc("0") Or KeyAscii > Asc("9") Then KeyAscii = 0
    End Sub

    I'd be more concerned with the fact that you have a RecordSet, and probably its underlying Table, with 200 Fields! Most experienced developers will tell you that a Table with more than 25-35 Fields is almost assuredly non-normalized.

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  3. #3
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    15,615
    I agree with Linq -- please tell us about your table(s) and what exactly you are trying to do.

  4. #4
    amd711 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Oct 2012
    Posts
    28
    Believe me, this table cannot be normalized any more
    I cannot describe it, but think of it as something with 200 immanent characteristics

  5. #5
    orange's Avatar
    orange is online now Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    15,615
    OK. If you can't describe it, there's not much advice/assistance we can offer. You could post the table layout.

  6. #6
    amd711 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Oct 2012
    Posts
    28
    OK. If you can't describe it, there's not much advice/assistance we can offer. You could post the table layout.
    My problem is programmatic, this is why i am posting in the programming section - it is not about my database design

    However, Thanks.

  7. #7
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,053
    One thing I've learned in 20 years of DB Development is a fresh pair of eyes can find something I a)didn't realize or b)didn't notice. I have to agree with the other responders recheck your table design. Other than that there really isn't anything else you can do.

  8. #8
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,001
    Everything else aside, as I originally said, you're talking about replacing one line of code, in the KeyPress event of each of your Textboxes, with one line of code, in the KeyPress event of each of your Textboxes! If you placed your code in a generic Function, you'd still have to Call that Function from each Textbox. There's simply no getting around this, although I've seen people trying to for years, now!

    Of course, if the Fields are defined as Numbers, Access won't allow Alpha characters to be saved to the Fields, but that only becomes obvious after the fact, so to speak, and the Access error message isn't very user-friendly! You could, of course, replace the Access error message with one of your own, and you'd only have to have the code for this in one place, the Form_Error event. Something like this:

    Code:
    Private Sub Form_Error(DataErr As Integer, Response As Integer)
    
    If DataErr = 2113 Then 'Data entered does not match datatype of Control Source
    
     Response = MsgBox("This Field Only Accepts Numeric Values!", vbExclamation, "Please Enter Numbers Only")
     Response = acDataErrContinue
     Me.ActiveControl.SelStart = 0
    
    End If
    
    End Sub


    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 10-23-2012, 09:04 AM
  2. Replies: 5
    Last Post: 08-28-2012, 03:23 PM
  3. Form - CANNOT EDIT TEXTBOXES !!!
    By dbalilti in forum Access
    Replies: 5
    Last Post: 07-05-2012, 12:15 PM
  4. Replies: 6
    Last Post: 06-12-2012, 06:30 AM
  5. Replies: 1
    Last Post: 11-07-2010, 11:04 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums - Senior Forums