473,471 Members | 2,005 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Auto generation from main form to sub form

12 New Member
Expand|Select|Wrap|Line Numbers
  1. Private Sub Specimen_ID_GotFocus()
  2. 'Get the next Spec ID
  3. Dim NextSpecID As String
  4. Dim CurrSpecID As String
  5.  
  6. 'Get the last 3 characters from the last specimen ID belonging to this project number
  7. CurrSpecID = Nz(Right(DMax("[Specimen ID]", "Spec", "[Project Number] = '" & Me.Project_Number & "'"), 3), 0)
  8.  
  9. 'Increment the ID by 1
  10. NextSpecID = Nz(CurrSpecID, 0) + 1
  11.  
  12. 'Add in zeros until it's 3 characters long
  13. Do Until Len(NextSpecID) = 3
  14.     NextSpecID = "0" & NextSpecID
  15. Loop
  16.  
  17. 'Build the next ID.
  18. NextSpecID = Format(Date, "yy") & "-" & Me.Project_Number & "-" & NextSpecID
  19.  
  20. 'Now put it in the form
  21. Me.[Specimen ID] = NextSpecID
  22.  
  23. End Sub
  24.  
Hello, I am using MS access 2003. I have a "Project Number" mentioned on the Main form, which is to be filled manually. I have linked a text box named "Specimen ID" from the subform to the "Project Number".Relation between Project Number and Specimen ID is ONE to MANY. Specimen Id has a format like - "12-201213-001"
In this, 12 stands for the current year, 201213 stands for the project number, and 001 stands for the number of specimen id under that particular project number.
as i click on the next row under specimen id, it automatically generates next specimen id as 12-201213-002. The code used for the same is as stated above.
The problem is that i am not able to modify "Specimen ID" as 12-201213-001A and 12-201213-001B and so on. If i try to do it, it shows a RUN TIME ERROR "13".
I feel that i will have to use the If-Then-Else loop, but i am not able to frame it properly as i am a novice in coding. Please help me with it.
Dec 28 '12 #1
4 2336
NeoPa
32,556 Recognized Expert Moderator MVP
I'm not inclined to delete this because you've clearly gone to some effort in trying to provide relevant information.

Unfortunately, it isn't really a question and your code has been posted as a picture.

Please post the code correctly (As text in [ CODE ] tags) and tell us what your question actually is. To be clear, a question is not a question if it is merely in the form "Here is my code - Please fix it for me". We need an actual question.

NB. If your response doesn't provide the question adequately then I expect my response will be to delete the thread, so this is likely to be your only chance to get it right in this thread.
Dec 28 '12 #2
Anjani
12 New Member
I hope its clear now...
Dec 28 '12 #3
zmbd
5,501 Recognized Expert Moderator Expert
Runtime error 13: Type mismatch.
Also: When posting your errors please post the EXACT number and text. There are are a few error messages where this is critical information as the wording or the numbers are slightly different from each other.


I betcha that if you will place the STOP at line 5 in the code block, then [F8] step thru the code that you'll find your error.

At some point in your code you've tried to assign a string or date etc... to a declared numerical or some other misdeclared data-type to assignment. This is either as a variable in your code or as a field in one of your tables.
Dec 29 '12 #4
NeoPa
32,556 Recognized Expert Moderator MVP
Anjani:
I hope its clear now...
The inclusion of the code is a definite improvement, but you still need to include the actual error message, the line the error occurred on, and the actual question you want answered. Please read my earlier post for why your original post is not considered a question.

PS. Please understand that, as I have already made it clear what is required for this to be considered as a question and that it may well be deleted if such information isn't forthcoming, this will still happen regardless of any other posts from members attempting to be helpful. This is a pre-requisite. This is not a 'nice to have' if other conversations fail you.
Dec 31 '12 #5

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

Similar topics

3
by: MatGyver | last post by:
I am going nuts trying to figure this out, any help will be appreciated. I have an existing table called "Parts". And in this table I have the following columns: "ID" "Part Number" "Part...
3
by: fh1996 | last post by:
Form.Owner and Form.Parent, what's the difference between them? Form.ShowDialog() and Form.Show(), when to use which? Form.Activated(), what does it mean when saying a Form is "activated"? ...
0
by: Nick | last post by:
Hi, I would like to know how to attach a RichTextBox which auto scale with Windows Form? Thanks Nick
0
by: Greg | last post by:
Hello, I'm about to write a database application and I'm wondering how to approach it. Is it worth to use the database code auto-generation (VC# 2005) in the long run? Or at some point I'll be...
5
by: geoff | last post by:
I've got an add form with a link that opens a pop up window. The main add form has a drop down menu with items populated from a db. In the popup window, you can add additional items to the db, so...
2
by: James R Esposito | last post by:
I am trying to transition from Access97 to Visual Basic.net. My biggest challenge to date is the creation of a Main/Sub Form. In Access97 You create a main form and you can then insert a sub...
2
by: Colin Halliday | last post by:
I have a Word 2003 mail merge main document (form letter) that is linked to another Word document data source for the mail merge. If I open this doc using the Word GUI, it first asks me to...
3
by: manivelk | last post by:
Hi, I am manivel.. Am doing C#.Net project.. I want to display the auto generation of numbers in a text box starts from 1.. But i dont know how to implement this.. If any one knows plz inform me.....
1
by: sayeediqbal | last post by:
Dear All i have two form: 1) login.php 2) main.php I send info for oracle database login userid and password through login.php and call main.php through submit method. in main.php, I am...
8
by: gamazone | last post by:
hi to all is it possible to auto fill and auto login the facebook login form? i am developing a web application in which , user will in put his,say for facebook, login information in his home...
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
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...
0
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...
1
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.