473,473 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Number Format in Select Case

4 New Member
Hi,

1. I have one unbound textbox on a form (Text62).
2.The another textbox on a form is (Text60) & the control source is =Left([List22].[Column](0),2)
3. The third textbox on a form is (Text24) & the control source is =Left([List22].[Column](0),5) & [Text62] & Right([List22].[Column](0),4)+1

Now, I am using below code to call the number in 4 digit format from Text62 in VBA.I need number format which I think I am not able to give the expression after (me.text62= ?????)

If I give "00" it is working fine starting from 0100 but when I change the start value 0001 the answer is 00-01 & giving VB error.

Can anyone advice.

Expand|Select|Wrap|Line Numbers
  1. Private Sub List22_DblClick(Cancel As Integer)
  2.  
  3. Select Case Text60
  4.  
  5.     Case "BD"
  6.         Me.Text62 = "00"
  7. End Select
  8.  
  9. Me.BVCode = Me.Text24
Sep 17 '13 #1
3 1522
zmbd
5,501 Recognized Expert Moderator Expert
Which version of Access are you using.

What is the EXACT error NUMBER and TEXT. Please no generic, post the EXACT number and text of the error.

The code you posted is not really doing anything at all, other than setting the value of the control "Text62" to the string value of "00" if and only if the value of "Text60" is the exact value of "BD" - note case matters.
As for what this code does, as compared to what you describe in your post, there is no correlation. If this is some generic code snip you are trying to use as an example, please do not do that.... we can only provide relevant help if you provide the actual code.
Sep 17 '13 #2
tajuddin
4 New Member
Thanks ZMBD for taking time to write to me.

I am trying to have increment number on my form from a list. I have

I think the below points will give you clear picture of the database.

1. I have 3 tables:
a. tblBV
fields: BVID / BVCode / BVDate / CoNum / Preform
b. tblCoName
fields: CoID / PrefixCocode / CoNameCode
c. tblPreForm
fields: Preform
2. I have 3 Queries:
a. q-BV
fields: BVID / BVCode / BVDate / CoNum / Preform / PrefixCocode
b. q-CoCode
fields: CoID and another field as CoCode: [PrefixCocode] & "-" & [CoNameCode]
c. q-BVLkp
fields: BVCode with total as MAX and another field as Left([BVCode],2)with total as Group By

I am trying to have increment numbers together with company code.
I have 4 companies:
1. BCI 2. CMDC 3. HAPC 4.NAL
Short codes of the company:
1. BCI = BD 2. CMDC = CD 3. HAPC = AD 4. NAL = ND
I wanted to have increment numbers with short code of the company whenever we click on a list.
Example:
1. BD13-0001 2. BD13-0002 3. BD13-0003 and so on.
2. CD13-0001 and so on.
3. AD13-0001 and so on.
4. ND13-0001 and so on.
I am using below code on Double Click of list called list22 as given below.
Expand|Select|Wrap|Line Numbers
  1. Private Sub List22_DblClick(Cancel As Integer)
  2.  
  3. Select Case Text60
  4.     Case "AD"
  5.         Me.Text62 = "0"
  6.     Case "BD"
  7.         Me.Text62 = "0"
  8.     Case "CD"
  9.         Me.Text62 = "0"
  10.     Case "ND"
  11.         Me.Text62 = "0"
  12. End Select
  13.  
  14. Me.BVCode = Me.Text24
  15.  
  16. Select Case BVCodePrefix
  17.     Case "BD"
  18.         Me.CoNum = 1
  19.     Case "CD"
  20.         Me.CoNum = 2
  21.     Case "AD"
  22.         Me.CoNum = 3
  23.     Case "ND"
  24.         Me.CoNum = 4
  25. End Select
  26.  
  27. Me.Recalc
  28.  
  29. End Sub
  30.  
  31.  
  32. Private Sub List22_GotFocus()
  33.     Me.Refresh
  34.     DoCmd.GoToRecord , , acNewRec
  35.  
  36. End Sub
  37.  
  38.  
  39. Private Sub BVCode_AfterUpdate()
  40.  
  41. Select Case BVCodePrefix
  42.  
  43.     Case "BD"
  44.         Me.CoNum = 1
  45.     Case "CD"
  46.         Me.CoNum = 2
  47.     Case "AD"
  48.         Me.CoNum = 3
  49.     Case "ND"
  50.         Me.CoNum = 4        
  51. End Select
  52.  
  53. End Sub
Now, when we give “0” in select case of Text60, the numeric portion is incrementing fine after 0100 and so on. But if we start from 0001 it is giving error as “Run time error, the value you entered is not valid for this field”

Expand|Select|Wrap|Line Numbers
  1. Select Case Text60
  2.     Case "BD"
  3.         Me.Text62 = "0"
Sep 18 '13 #3
zmbd
5,501 Recognized Expert Moderator Expert
- Lines 3 thru 12 make no sense at this stage of your coding.
- "“Run time error, the value you entered is not valid for this field” Is this the entire error? If the second posted code is where the error is occurring, then check the control source property for "Text62." I suspect that this is bound to a table field that is typecast as a numeric and what you are entering is a string value ("0" - the quotes make this a string) hence the error.

What you should be doing is explicitly typecasting all of your variables, I prefer at the start of the code; however, others have different viewpoints.

Your first step to accomplishing this will be to follow the setup and troubleshooting section for VBA found here: > Before Posting (VBA or SQL) Code

Once you set your Option Explicit in the VBE options you will then need to add this to each of your existing forms and modules.

Until you type cast/define all of your variables the compiler will complain about this.... this may take you some time; however, it is the best practice.

Once you can compile your code without error, we can take the next steps.
Sep 18 '13 #4

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

Similar topics

0
by: David Engle | last post by:
I have created a form with 2 combo boxes. The purpose of the form is to export CR9 reports to selected types of formats (rpt, doc,xls, etc) and choose the destination for the report (mail, file,...
3
by: mark.irwin | last post by:
Hello all, Have an issue where a redirect pushes data to a page with a select case which then redirects to another page. Problem is the redirect isnt working in 1 case. Code below: strURL =...
3
by: Rob Meade | last post by:
Ok - I *think* this is only different in .net 2.0 - as I've not had any problems in the past, but then maybe I've not tried it... I have a value being read from an xml file where the value maybe...
3
by: Paul Bromley | last post by:
I have just started to use Classes a lot in my code. Often I find that I need to use the same contstructor, but wish to invoke a different action depending on where I am clling the class from. I...
8
by: | last post by:
Hello, This is gonna sound real daft, but how do I test a Select Case statement for variants of a theme? Here's a snippet of my code... Select Case sUsr Case "Guest", "TsInternetUser",...
7
by: Richard Hollenbeck | last post by:
How can a numeric field display results in fractions? If my recipe data requires 1/2 cup of something, for example, I'm willing to punch in 0.5 in the quantity field then select cup in the unit...
1
by: microsoft.public.dotnet.languages.vb | last post by:
Hi All, I wanted to know whether this is possible to use multiple variables to use in the select case statement such as follows: select case dWarrExpDateMonth, dRetailDateMonth case...
0
by: Wayne | last post by:
I am charting data from a query that consists of a Date/Time field and a Number field. The Date/Time field is the x scale on my chart. Sometimes data is collected from different times during the...
10
by: Dixie | last post by:
I am appending some new fields to a table in vba and when I append a number field with is a byte, it does not inherit any format. I want it to be the General Number format, but it is blank. I...
3
by: JaketheSnake27 | last post by:
I am completely stumped on what seems to be a completely simple thing. What I'm trying to do is use a SELECT CASE with a recordset. The SELECT CASE looks at one field from the recordset to establish...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.