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

Generate Auto Number

Hi

Im stuck AGAIN!!!!!! Sure its something simple but, Ive put together a code to generate an automatic number everytime i open the work book, However I now would rather only generate the number when I click on a particular button.

The code works fine when its in a Private Sub Auto Open(). ive copied the code directly into a command button code. Upon clicking it selects the right sheet but does not generate the new number.

This is what i Got

Private Sub ReqBut_Click()

Sheets("Orders Sent").Select

For Row = 2 To 64000
If Cells(Row, 1) = "" Then
GoTo RowSkip1
End If
Next Row

RowSkip1:

LastRow = Row - 1
Currentrow = Row
If LastRow < 10 Then
Cells(Currentrow, 1).Value = "AL" & 0 & 0 & 0 & LastRow
End If
If LastRow > 9 And LastRow < 100 Then
Cells(Currentrow, 1).Value = "AL" & 0 & 0 & LastRow
End If
If LastRow > 99 And LastRow < 1000 Then
Cells(Currentrow, 1).Value = "AL" & 0 & LastRow
End If
If LastRow > 1000 Then
Cells(Currentrow, 1).Value = "AL" & LastRow
End If


Worksheets("Chemicals").Range("d2").Value = Cells(Currentrow, 1).Value

End Sub



Any one have any ideas where im going wrong?
Also is there a shorter way of doing what ive done?

Thanks

Manny
Aug 2 '07 #1
1 1955
Hi

Im stuck AGAIN!!!!!! Sure its something simple but, Ive put together a code to generate an automatic number everytime i open the work book, However I now would rather only generate the number when I click on a particular button.

The code works fine when its in a Private Sub Auto Open(). ive copied the code directly into a command button code. Upon clicking it selects the right sheet but does not generate the new number.

This is what i Got

Private Sub ReqBut_Click()

Sheets("Orders Sent").Select

For Row = 2 To 64000
If Cells(Row, 1) = "" Then
GoTo RowSkip1
End If
Next Row

RowSkip1:

LastRow = Row - 1
Currentrow = Row
If LastRow < 10 Then
Cells(Currentrow, 1).Value = "AL" & 0 & 0 & 0 & LastRow
End If
If LastRow > 9 And LastRow < 100 Then
Cells(Currentrow, 1).Value = "AL" & 0 & 0 & LastRow
End If
If LastRow > 99 And LastRow < 1000 Then
Cells(Currentrow, 1).Value = "AL" & 0 & LastRow
End If
If LastRow > 1000 Then
Cells(Currentrow, 1).Value = "AL" & LastRow
End If


Worksheets("Chemicals").Range("d2").Value = Cells(Currentrow, 1).Value

End Sub



Any one have any ideas where im going wrong?
Also is there a shorter way of doing what ive done?

Thanks

Manny
Just something ive noticed,
The cells which i want updating dont show the number (on the Order Sheet)
but when i press the command button the cell d2 on the chemical sheet does change and increment as it should.
Aug 2 '07 #2

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

Similar topics

2
by: Laphan | last post by:
Hi All This is a strange request, but I just cannot fathom how to do it. In theory the requirement is very basic, but in practise its a noodle!! I have 10 team names like so: Team A Team...
2
by: Andrew Grandison | last post by:
We are converting a legacy visual foxpro system to use a SQL back-end. A number of (existing DBF) tables currently have a zero-filled primary key eg. '000255' which is just an auto-incrementing...
6
by: Sebastien | last post by:
Hi, I am building a products database, linking sales and production. Each part has a unique sales Stock Code and Production Number. The sales stock code is a combination of letters and numbers...
2
by: SalimShahzad | last post by:
Dear Gurus, i had written following codes to auto generate the next claim no Private Const strC = "GCT/02/J/" Private Sub Command1_Click() Dim stra, stre As String Dim intb, intd As Integer...
11
by: Alan Mailer | last post by:
A project I'm working on is going to use VB6 as a front end. The back end is going to be pre-existing MS Access 2002 database tables which already have records in them *but do not have any...
3
by: arun_kumar112 | last post by:
dear sir, i wish to generate auto number starting from 1000 to 1000000. but each time number automatically generated no duplicate number generate assign. thanks, arun kumar
2
by: G | last post by:
Hello Firends I want a sample code for developing an " auto genearte number " and want to store in database. Please if you find any code please send Thanks in Advance G
4
by: Michiel Rapati-Kekkonen | last post by:
Hi, I would like to generate a versionnumber (and save it in a internal table) on the moment I make a mde. Then there would also be such version tabel in the central, linked data mdb. When...
1
by: abhaya9999 | last post by:
Hi all i am new to mysql and php. i want an urgent help. i am developing an application for an training centre. i want to maintain a student table. To which i only enter his/her name and...
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
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
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...

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.