473,587 Members | 2,580 Online
Bytes | Software Development & Data Engineering Community
+ 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 1527
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
666
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, etc.). What is the best method to state if selectedindex 1 and selectedindex 2 are selected so that then the export methods is carried out according...
3
3386
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 = "" if i = 1 then strURL = "redirect.aspx?page=APIQ&parcel=" & strParcel &
3
3765
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 a word or a number, ie... Low or 1 Medium or 2 High or 3
3
1237
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 hav therefors started sending an extra parameter to initialise the Class that I tend to call sArea. I then use this in my code with a series of Select...
8
4715
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", "krbtgt", "quality7" ' don't show
7
15783
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 field, but it is more aesthetically cool to display the number like any paper cook book would--in plain old regular fractions. I didn't see a format...
1
21657
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 "01" : dWarrExpDateMonth="Jan" : dRetailDateMonth="Jan" case "02" : dWarrExpDateMonth="Feb" : dRetailDateMonth="Feb" End Select
0
2498
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 one day. I need to be able to see these times as different time points on the x scale of my chart. To accomplish this I am using the following...
10
13706
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 have tried to change the format with the following code, but it does not work. What is wrong with this code and how can I make that byte number field...
3
5463
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 the CASE's. I looked at the table that this field comes from and the field's data type is "text." When I make my CASE's, the program runs fine if I...
0
7843
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7967
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6621
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5392
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3840
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3875
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2353
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 we have to send another system
0
1185
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.