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

How can I create a unique ID for a new batch set of values

I'm currently using Visual Basic code to insert values into a temporary table
and am looking to change one thing. When I add the values sometimes I will
just add one value at a time or sometimes it could be more, there is no limit.
Each time I add these values I would like to have a unique ID attached to
each value that is added at that specific time, kind of like a batch ID. I
was thinking the way to do this would be to use a '+1' formula or something
like that. Is this the best way? Would I need to do some kind of lookup for
the highest ID and then do the '+1'? I am far less sure about using Visual
Basic for these things than SQL! Here is my current code:
Expand|Select|Wrap|Line Numbers
  1.    varNotes = Me.txtNotes
  2.    lngLocID = Me.cboLocID
  3.    lngActID = Me.cboActID
  4.    lngActName = Me.txtActivityName
  5.    lngPrjBox = Me.cboProjectBox
  6.    Set db = CurrentDb
  7.    If Me.grpRepeats = 2 Then 'need to loop through dates
  8.        For datThis = Me.txtStartDate To Me.txtEndDate
  9.            intDIM = GetDIM(datThis)
  10.            intDOW = Weekday(datThis)
  11.            If Me("chkDay" & intDIM & intDOW) = True Or _
  12.                    Me("chkDay0" & intDOW) = True Then
  13.                strSQL = "INSERT INTO tbl_temp_schedule_dates ( tscDate,
  14. tscActID, tscLocID, tscActivityName, tscProjectBox, tscStartTime, tscEndTime,
  15. tscNotes ) " & _
  16.                    "Values(#" & datThis & "#," & lngActID & ", " & _
  17.                    lngLocID & ",""" & lngActName & """," & lngPrjBox & ", #"
  18. & Me.txtStartTime & "#, #" & _
  19.                    Me.txtEndTime & "#," & _
  20.                    IIf(IsNull(varNotes), "Null", """" & varNotes & """") & ")
  21. "
  22.                db.Execute strSQL, dbFailOnError
  23.            End If
  24.        Next
  25.     Else  'dates are there, just add the title, notes, times, location,
  26. Activity
  27.        strSQL = "Update tbl_temp_schedule_dates Set tscActID = " & lngActID
  28. & _
  29.            ", tscActivityName = """ & lngActName & """, tscProjectBox = " &
  30. lngPrjBox & _
  31.            ", tscLocID = " & lngLocID & ", tscStartTime =#" & Me.
  32. txtStartTime & _
  33.            "#, tscEndTime = #" & Me.txtEndTime & "#"
  34.  
  35.        If Len(varNotes & "") > 0 Then
  36.            strSQL = strSQL & ", tscNotes = " & IIf(IsNull(varNotes), Null,
  37. """" & varNotes & """")
  38.        End If
  39.        db.Execute strSQL, dbFailOnError
  40.    End If
  41.    Me.sfrm_temp_schedule_edit.Requery
  42.    MsgBox "Temporary schedule built. " & _
  43.        "You can now edit the schedule and " & _
  44.        "append to the permanent schedule.", vbOKOnly + vbInformation, "Temp
  45. schedule complete"
  46. End Sub
  47.  
Aug 24 '10 #1
1 2226
NeoPa
32,556 Expert Mod 16PB
Russ:
Iwas thinking the way to do this would be to use a '+1' formula or something like that. Is this the best way? Would I need to do some kind of lookup for the highest ID and then do the '+1'?
Essentially you're right Russ.

Use DMax() to find the maximum value of whichever field you store the Batch ID in then add one to this and use it as your new Batch ID.

Welcome to Bytes!
Aug 24 '10 #2

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

Similar topics

1
by: Antonio Lopez Arredondo | last post by:
hi ! system.io.path.gettempfilename() returns a unique file name in the TEMP folder. does anybody know how to create a unique file name in another folder ? thanks in advance, ant.
4
by: ScoobyDoo | last post by:
Anyone know how I can create and edit batch files from MS Access 2002?
4
by: Jason Shohet | last post by:
A user runs a .NET application that authenticates them against active directory (they're coming in over VPN so they don't log on to the network normally). Once they log in, I want to take their...
1
by: Prince | last post by:
Hi all, Can anyone tell me how to create auto generated values in a DataTable column? Looking forward for the reply.... Thanx in advance...
31
by: louishong | last post by:
3rd time posting this as the first two simply disappeared! Here's the issue: We currently run an Access application in the West Coast for tracking resource centric data. For those located in the...
1
by: Asko Telinen | last post by:
Hi all. I´m a bit newbie writing xml schemas. Is it possible to define xml element that must have unique attribute values in same level. For example if i have a xml - document: <list>...
10
by: rousseaud | last post by:
Hello- I'm having a little trouble. I want to create a query that will return the most recent records (by date) for all unique values in a certain field in the query. I'll be pulling data from 3...
4
Ispep
by: Ispep | last post by:
Hi, unfortunately having a bit of difficulty with a question from an Open University course I'm currently doing. If you could help me out in any way I'd be grafeul (though obviously it goes without...
1
newnewbie
by: newnewbie | last post by:
Desperately need help in creating a query to count unique values in a table. I am a Business analyst with limited knowledge of Access….My boss got me ODBC connection to the underlying tables for our...
6
by: Alvin SIU | last post by:
Hi all, I have a table in Db2 v8 like this: Team Name Role ------ -------- --------------------- A Superman Leader A Batman Member A WonderWoman Member B ...
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
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
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
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
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...
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...

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.