473,441 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,441 software developers and data experts.

VB question on Access form

You may be familiar with this problem as I posted it before, so here we go...

I have a module that provides error checking for the length of a SSN and I need a
little help in one area...

The code will check to see if the SSN is 9 digits exactly, and if not it will produce an error message, otherwise it will cipher the SSN. The error message is part of the VBA (the 'msg' in the code below).

My question is how can I get the code to work so it will still check for 9 digits (for use in a form) but also accept an empty string (when opening a report) and NOT produce the same error message?

Thanks

My code is here:

Expand|Select|Wrap|Line Numbers
  1. Public Function CipherSS(SSN As String)
  2.    Dim Mask As String, Build As String, x As Integer
  3.    Dim Msg As String, Style As Integer, Title As String, DL As String
  4.  
  5.    DL = vbNewLine & vbNewLine
  6.  
  7.    If Len(SSN) <> 9 Then
  8.       Msg = "SSN Must Be Exactly 9 Digits!" & DL & _
  9.             "Check SSN '" & SSN & "' and try again . . ."
  10.       Style = vbInformation + vbOKOnly
  11.       Title = "SSN Not 9 Digits Error! . . ."
  12.       MsgBox Msg, Style, Title
  13.       CipherSS = Null
  14.    Else
  15.       Do
  16.          x = x + 1
  17.  
  18.          If Asc(Left(SSN, 1)) < 58 Then
  19.             If (x Mod 2) = 0 Then
  20.                Mask = 64
  21.             Else
  22.                Mask = 32
  23.             End If
  24.          Else
  25.             If (x Mod 2) = 0 Then
  26.                Mask = -64
  27.             Else
  28.                Mask = -32
  29.             End If
  30.          End If
  31.  
  32.          Build = Build & Chr(Asc(Mid(SSN, x, 1)) + Mask)
  33.       Loop Until x = 9
  34.  
  35.       CipherSS = Build
  36.  
  37.    End If
  38.  
  39. End Function
Aug 27 '07 #1
8 1728
Scott Price
1,384 Expert 1GB
Instead of:
Expand|Select|Wrap|Line Numbers
  1. If Len(SSN) <> 9 Then
try:
Expand|Select|Wrap|Line Numbers
  1. If Not IsNull(SSN) AND Len(SSN) <> 9 Then

Regards,
Scott
Aug 27 '07 #2
that didn't seem to work.

I still get the "Must be 9 digits error" coming up when I try to open the report with a "0" or empty string in the SSN field. still trying to figure this one out.

thanks
Aug 27 '07 #3
Scott Price
1,384 Expert 1GB
that didn't seem to work.

I still get the "Must be 9 digits error" coming up when I try to open the report with a "0" or empty string in the SSN field. still trying to figure this one out.

thanks
You must have your default value set to not accept nulls...

Try:

Expand|Select|Wrap|Line Numbers
  1. If SSN<>"0" AND SSN<>"" AND Len(SSN) <> 9 Then
Regards,
Scott
Aug 27 '07 #4
missinglinq
3,532 Expert 2GB
I'm confused! The technical aspect of getting the report to accept an invalid SSN aside, if you have your form set up so as to require that a valid SSN be entered, why would you need your report to accept a non-valid SSN? How is a non-valid SSN going to be entered into your table?

Linq ;0)>
Aug 27 '07 #5
I'm confused! The technical aspect of getting the report to accept an invalid SSN aside, if you have your form set up so as to require that a valid SSN be entered, why would you need your report to accept a non-valid SSN? How is a non-valid SSN going to be entered into your table?

Linq ;0)>

heres how it works:
1. OPTIONAL TO USER: ssn entered on form
2. ssn saved in table when record saved from form
3. on opening the report, the reports control source is a query that uses the module code previously posted to verify if the ssn is not null, but will still open the report even if there are blank (empty string) ssn's.
4. because the report is based off a query, and that query has "built-in" error checking using the module, it will still produce the error message contained in the code ("SSN Must be Exactly 9 Digits")

i want to get it so i can still open the report and NOT receive the error message for an empty string...thats all

hope that helps
thanks
Aug 27 '07 #6
Scott Price
1,384 Expert 1GB
My question is how can I get the code to work so it will still check for 9 digits (for use in a form) but also accept an empty string (when opening a report) and NOT produce the same error message?
I guess I read the question backward, and assumed the error was being generated whenever opening a form to enter a new SSN...


Regards,
Scott
Aug 27 '07 #7
I guess I read the question backward, and assumed the error was being generated whenever opening a form to enter a new SSN...


Regards,
Scott

no problem, but does anyone have a solution? i'm continuing to work on it but to no avail.
Aug 27 '07 #8
Scott Price
1,384 Expert 1GB
no problem, but does anyone have a solution? i'm continuing to work on it but to no avail.

Did you try the code I posted in post #4?

You don't have this same msgbox being called somewhere else, do you? Like in the On Open event of the report, etc...

Regards,
Scott
Aug 27 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Hamed | last post by:
Hello I have employed as a developer in a software company that its team uses FoxPro / VB 6.0 / VC++ 6.0 as the developing tools and newly is going to migrate to VS.NET. There is a project...
7
by: Mike Dwyer | last post by:
I need a VB 6 app to automate a microsoft access MDB application. Specifically, it needs to open a form in Access and read information keyed into that form. I know this is "old school" but I'm...
13
by: Manuel Lopez | last post by:
I have a puzzling form timer problem that I didn't experience prior to Access 2003 (though I'm not sure access 2003 is to blame). Here's the situation: a computer has two access 2003 databases on...
49
by: Yannick Turgeon | last post by:
Hello, We are in the process of examining our current main application. We have to do some major changes and, in the process, are questionning/validating the use of MS Access as front-end. The...
20
by: Olav.NET | last post by:
I am a .NET/C++ developer who is supposed to do some work with Access. I do not know much about it except for the DB part. Questions: *1* I am looking for INTENSIVE books to get quickly up to...
3
by: dixie | last post by:
I have an Access 2000 form which has been running OK for a long time. Lately, it is playing up and doing things like causing Access to close suddenly when the form is opened or when saving the form...
2
by: rdemyan via AccessMonster.com | last post by:
I have a custom message form that I want to display when the user shuts down my app. Some clean up needs to be done during shutdown and I want to display this form and then display various...
14
by: ApexData | last post by:
I am considering building some distributable commercial applications. For about a year now, I have been using Access2000. This was my first venture into object oriented database development. ...
9
by: prakashwadhwani | last post by:
Hi !! I'm about to develop a new project for a client. Should I go about it in Access 2003 or 2007 ? Purchasing it either for me or for my client is not a major consideration here ... what I'd...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.