954,566 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to update if user want to add data in between data like insert row above in excel

Hi all,
I have a table where it stores Process.
The Process has each processNumber which is unique,
& the processNumber indicates the step of a procedure.

My problem is, user request to add a Process in between existing processes.
In other word the new Process overwrite the existing process number, & the others existing need to be updated to processnumber+1

What is the best way to do this in VBA access?, if you get what i'm saying
Thanks

isumasama
Newbie Poster
18 posts since Feb 2006
Reputation Points: 11
Solved Threads: 0
 

Copy this function into a standard module (not form, report or class) and name the module something other than the name of the function:

Function AdjustProcNum(strTableName As String, strFieldName As String, lngNewNum As Long)
   Dim strSQL As String
   Dim rst As DAO.Recordset

strSQL = "Select [" & strFieldName & "] From [" & strTableName & "] " & _
         "ORDER BY [" & strFieldName & "]"

Set rst = CurrentDb.OpenRecordset(strSQL)

Do Until rst.EOF
   If rst(strFieldName).Value >= lngNewNum Then
      rst.Edit
      rst(strFieldName).Value = rst(strFieldName).Value + 1
      rst.Update
   End If
   rst.MoveNext
Loop

MsgBox "You can now enter the new process number " & lngNewNum, vbInformation

rst.Close
Set rst = Nothing   
End Function
boblarson
Junior Poster in Training
79 posts since Jan 2008
Reputation Points: 31
Solved Threads: 8
 

I forgot to include how to call this.

It should be:

Call AdjustProcNum("YourTableNameInQuotes", "YourFieldNameInQuotes", YourNewNumber)

boblarson
Junior Poster in Training
79 posts since Jan 2008
Reputation Points: 31
Solved Threads: 8
 

hi boblarson
great answer! thanks a lot

isumasama
Newbie Poster
18 posts since Feb 2006
Reputation Points: 11
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: