[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

MS Access Number value can't start with zero

Posted on 2007-07-24
7
Medium Priority
?
313 Views
Last Modified: 2007-07-24
I  a combo box "cboSku" where the values select or entered can not start with zero. I need to set up a trigger if the person starts by entering a zero, telling them that item number can't not start with a zero. I don't know how the coding should be. Never tried a validation like this before.  
0
Comment
Question by:jumpy262000
  • 4
  • 2
7 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 1000 total points
ID: 19557663
Private Sub cboSKU_Change()

   If Left(Me.cboSKU,1)=0 then
      ' message here
     SendKeys "{BACKSPACE}"
   Endif

End Sub

mx
0
 
LVL 75
ID: 19557676
So ... add this code to the On Change event  

Private Sub cboSKU_Change()

   If Left(Me.cboSKU,1)=0 then
     Beep                                        '**** Add a BEEP
      ' message here
     SendKeys "{BACKSPACE}"
   Endif

End Sub
0
 
LVL 75
ID: 19557688
" I need to set up a trigger if the person starts by entering a zero"
You can also use the BeforeUpdate:


Private Sub cboSKU_BeforeUpdate(Cancel As Integer)

   If Left(Me.cboSKU,1)=0 then
     Beep                                        '
      ' message here
     Cancel = True
     Exit Sub
   Endif

End Sub

0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 1000 total points
ID: 19557756
this code will prevent entering 0 as the first digit

Private Sub cboSku_KeyDown(KeyCode As Integer, Shift As Integer)
If Len(Me.cboSku.Text) = 0 Then
    If KeyCode = 96 Or KeyCode = 48 Then
        KeyCode = 0
    End If
End If
End Sub

as for the selecting of values, just make sure that the values in the field for the Rowsource doesn't have a zero as prefix.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 19557800
or you can use this too

private sub cbosku_exit(cancel as integer)

me.cbosku=val(me.cbosku)
end sub
0
 
LVL 1

Author Comment

by:jumpy262000
ID: 19557897
Thanks, you're answers/suggestions help a lot.
0
 
LVL 75
ID: 19557951
you are welcome.
You now have various ways to handle variations of this kind of validation ...

mx
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question