Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old November 13th, 2005, 11:03 AM
simonmarkjones@gmail.com
Guest
 
Posts: n/a
Default 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!

  #2  
Old November 13th, 2005, 11:03 AM
Beacher
Guest
 
Posts: n/a
Default Re: Increment a number then add back to table

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?
simonmarkjones@gmail.com wrote:[color=blue]
> 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[/color]
in[color=blue]
> a textbox on a form first.
>
> Cheers![/color]

  #3  
Old November 13th, 2005, 11:03 AM
simonmarkjones@gmail.com
Guest
 
Posts: n/a
Default Re: Increment a number then add back to table

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

  #4  
Old November 13th, 2005, 11:03 AM
Beacher
Guest
 
Posts: n/a
Default Re: Increment a number then add back to table


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

  #5  
Old November 13th, 2005, 11:03 AM
simonmarkjones@gmail.com
Guest
 
Posts: n/a
Default Re: Increment a number then add back to table

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.

  #6  
Old November 13th, 2005, 11:03 AM
Beacher
Guest
 
Posts: n/a
Default Re: Increment a number then add back to table

My first too :)... No problem, glad I could help!

 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles