473,396 Members | 1,734 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,396 software developers and data experts.

ON CLICK event working on DOUBLE CLICK

12
Hello,

My FORM has 3 main components along with other components in it.

1. Project Number (Text Box)
2. Created Date (Text Box)
3. Specimen ID (Text Box)

Specimen ID has prespecified format to follow i.e. "YY-Project Number-001" where "YY" is last two digits of the Year pulled from CREATED DATE. "001" is the increamental number which should be populated ON CLICK in the SPECIMEN ID text box. When i click on the next column of the Specimen ID it should populate as "YY-Project Number-002".

I have written the following code at ON CLICK event of the SPECIMEN ID text box: -
Expand|Select|Wrap|Line Numbers
  1. Private Sub Specimen_ID_Click()
  2. 'Get the next Spec ID
  3. Dim NextSpecID As String
  4. Dim CurrSpecID As String
  5.  
  6. On Error Resume Next
  7.  
  8.  
  9. 'Get the last 3 characters from the last specimen ID belonging to this project number
  10. CurrSpecID = Nz(Right(DMax("[Specimen ID]", "Spec", "[Project Number] = '" & Me.Project_Number & "'"), 3), 0)
  11.  
  12. 'Increment the ID by 1
  13. NextSpecID = Nz(CurrSpecID, 0) + 1
  14.  
  15. 'Add in zeros until it's 3 characters long
  16. Do Until Len(NextSpecID) = 3
  17.     NextSpecID = "0" & NextSpecID
  18. Loop
  19.  
  20. 'Build the next ID.
  21. NextSpecID = Format(Me.Created_Date, "yy") & "-" & Me.Project_Number & "-" & NextSpecID
  22.  
  23. 'Now put it in the form
  24. Me.[specimen Id] = NextSpecID
  25.  
  26.  
  27.  
  28. End Sub
  29.  
  30.  
The problem is that when i click once on the Specimen ID column, it displays "--001" and when i click again at the same place, it gives the desired output.

This should happen in 1 click.

Kindly help.

Thanks
Jan 18 '13 #1
4 3295
Rabbit
12,516 Expert Mod 8TB
Most likely this is because the record has not been created yet and there are no values in those other fields you're trying to reference. Instead of referencing those other fields, take what the default values would be and code that in place of the reference.

Also, you probably shouldn't run the code on click. What happens if they accidentally click in there? Instead, you should populate the default value.
Jan 18 '13 #2
Anjani
12
other two values are always produced before clicking on Specimen ID.
I want the format to generate on click and hence the code has been written on the CLICK event.
Please help.
Jan 18 '13 #3
zmbd
5,501 Expert Mod 4TB
Please do the following:

Read the first section of: Before Posting (VBA or SQL) Code take care of any compiler errors. Your formatting is fine; however, I just want to make sure the other settings are correct so that we're on the same page. Reading the remainder of the link would also be helpful.

Second, let's see what you are actually getting in your code:
using the posted code block as reference:
insert at line 11 debug.print "--" format(now(),"yyyy-mm-dd hh:nn")
Following the above inserted at line 11 debug.print "CurrSpecID: " & CurrSpecID
insert at line 14 debug.print "NextSpecID: " & NextSpecID
insert at line 19 debug.print "NextSpecID: " & NextSpecID
insert at line 22 debug.print "NextSpecID: " & NextSpecID
insert at following the above insert at line 22 debug.print "---"

Run your code three times via the click event.
From the main Access window press <ctrl><g>
In the debug window, copy and paste the results back here.

I want the format to generate on click and hence the code has been written on the CLICK event.
"I Want..." comes across a tad harsh. Thus, I would caution you on the potentially perceived tone in the way this is worded. It would have been maybe better to have provided a reasoning behind the need/desire to have the onclick event handle this code for you. Rabbit has a great deal of experience with database and software design and as such, the suggestions made by Rabbit should be taken with some consideration. Indeed, you have access to a consultant that could be costing you several hundreds of US-Dollars per hour!
Jan 18 '13 #4
NeoPa
32,556 Expert Mod 16PB
Indeed Anjani. You ignore the advice of Rabbit at your peril. There is very little chance that it makes sense to update this value when the control is clicked. The DefaultValue property is always a better bet. When to set it should technically be after the operator has already committed the data to the table, but many people prefer that the operator can see it, so prepare it in advance. This allows for the possibility, in a multi-user environment, that the save can fail due to the re-use of the same ID. So, if you want the operator to see the value then you should set the DefaultValue in the Form_Current() event procedure, but if you really want to do it properly you set it (The value in this case.) in the Form_BeforeUpdate() event procedure.

If you follow Z's advice about debugging your procedure, you'll have some very helpful information about which parts of your code is behaving in a way you're not anticipating, which will allow you to focus on that particular area.
Jan 20 '13 #5

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

Similar topics

0
by: Andreas Müller | last post by:
Hi All, I have a control derived from UserControl. Now I would like to distinguish between a click and a double click event on my control. The problem is, that on a doubleclick, the control...
1
by: Sakharam Phapale | last post by:
Hi All, How to capture Mouse Single click and mouse double click event on Commnad Button. I am doing as follows. Private void Button1_MouseUp(Object sender,...
4
by: John | last post by:
how to add an event click to button in C# using visual studio 2003 i know i can double click on the button but is there any other way through the code?
1
by: Tuvas | last post by:
I am trying to execute a function with a tkinter event binding double click. With 2 mouse clicks done quickly, the function should happen, otherwise, it should not. However, I am noticing that the...
2
by: Chu | last post by:
Thanks everyone for taking a moment to read this. I've got a page where I use a LinkButton and I wire up a dynamic event to the button. When the user clicks the button, the event is fired as...
9
by: Armando | last post by:
I have an app (A2000) where I am letting the user move an object on the screen. I use the OnClick for a command button event to modify the object's Top (or Left) properties, but you can only click...
3
by: Techsatish | last post by:
how to make a mouseup event called only once during a double click event? here double click is made on a tree node in a tree control. I have the code inside mouseup event....in runtime the...
2
by: cumars | last post by:
Hello Friends, I want to trigger both the click event and double click event in a single button separately. (i.e.) the user can trigger both the single click and the double...
1
by: spwanxander | last post by:
The big problem that I am having is that I have a asp.net support manager website that I am building. One of my pages has a couple of buttons on it. The first button is and "add" or can be changed...
6
by: Jim Devenish | last post by:
I have an unbound form that displays all the days of the year as a calendar. It has 12 rows of text boxes with either 29,30 or 31 in each row. Text box names are of the form: display_01_01,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...

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.