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

Increment a number then add back to table

Hi am very new to programing VBA in Access.

I'm trying to increment a number stored in a table.
So far i've got.

Function IncrementLastUsedNumber()
Dim myNumber As Integer

myNumber = DMax("[LastUsedNumber]", "tableLastUsedNumber")+1
End Function

I now need to be able to write this new value back to the table over
the previous number.

I want to be able to do this with VBA rather than storing the value in
a textbox on a form first.

Cheers!

Nov 13 '05 #1
5 2023
Could you not just use SQL to write the variable back to the table?
Dim strSQL AS String
strSQL = "SQL CODING HERE"
DoCmd.RunSQL(strSQL)

Something like that?
si************@gmail.com wrote:
Hi am very new to programing VBA in Access.

I'm trying to increment a number stored in a table.
So far i've got.

Function IncrementLastUsedNumber()
Dim myNumber As Integer

myNumber = DMax("[LastUsedNumber]", "tableLastUsedNumber")+1
End Function

I now need to be able to write this new value back to the table over
the previous number.

I want to be able to do this with VBA rather than storing the value in a textbox on a form first.

Cheers!


Nov 13 '05 #2
Probably but don't know any SQL either.

Never had to do this befor but work needs it done by friday.

Want to use it for an autogenerated number of a certain format.

I've coded all the other parts to this just not sure how to add back to
database.

Sorry

Nov 13 '05 #3

Dim strSQL AS String
strSQL = "UPDATE tblName SET fieldName = " & myNumber & " WHERE
fieldName2 = 'criteria' "
DoCmd.RunSQL(strSQL)

I don't know if you want to replace this number in every row of your
table.. if so then take off the word WHERE and on

Nov 13 '05 #4
Wow that helped thankyou.

Guess i'll have to tech myself some SQL now.

My first newsgroup message ever as well. Thanks for the quick response!

Have a good day.

Nov 13 '05 #5
My first too :)... No problem, glad I could help!

Nov 13 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Randell D. | last post by:
Folks, I have a table of addresses and a seperate table with contact names - All addresses tie to one or more names - I would like to keep track of the number of names 'belonging' to an address...
7
by: Yannick Turgeon | last post by:
Hello all, I'm using SS2K on W2k. I'v got a table say, humm, "Orders" with two fields in the PK: OrderDate and CustomerID. I would like to add an "ID" column which would be auto-increment...
2
by: Tom | last post by:
I am trying to store information into a table that has an auto increment field. There is currently no data in the table. Using the code below I cannot insert data into the table. I get an error...
3
by: Scott | last post by:
I have a database with an input form. The field "DailyID" on the form is to increment automatically with each new entry, then reset itself back to "1" at midnight and/or the change of date. ...
3
by: nfrjob | last post by:
Hi there, I'm an advanced beginner, so please bear with me... I have a simple table that has four fields in it: Zone (which will store a three letter code such as ABC), Year (a four digit number...
12
by: badvoc | last post by:
Hi, I have had some good fortune on this site so I am back and I must iterate I am a beginer. I am having some problems getting to grips with the right technique to manage variables and...
1
by: Studiotyphoon | last post by:
HI, I have two tables which currently have Autonumber fields which are used to create a unique number to identify an invoice for each table. Instead of having two unique numbers I'm after only...
11
by: ZaphodBBB | last post by:
Hi I have a table that has as its Primary Key the Auto-Increment Field: Equipment_Number. In M.S. Access is there any way to define a starting number for the field? OR another way in which...
5
by: David Wright | last post by:
Hello Everyone I would be grateful if someone could help me with the automatic increment of a field on my subform called ‘Test_SrNo’. I am Using Microsoft Office 2000. The auto entry of the...
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: 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
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
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
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,...

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.