ClaraBarton
Registered User.
- Local time
- Today, 05:35
- Joined
- Oct 14, 2019
- Messages
- 754
I know how to get the ID (DMax) of a new record but I fill in (Update) unused records that aren't in the form recordset until the checkbox inuse is positive.
I'm stumped as to how to get the ID if it isn't a new record. These records aren't included in the forms recordset until the table is requeried.
I need to know the ID to position to the added (updated) record.
	
	
	
		
 I'm stumped as to how to get the ID if it isn't a new record. These records aren't included in the forms recordset until the table is requeried.
I need to know the ID to position to the added (updated) record.
		Code:
	
	
	Public Sub AddItem(ID As Long, strITPath As String)
    Dim strCriteria               As String
    Dim lDocNo                  As Long
    Dim strSql                     As String
    Dim rst                         As DAO.Recordset
    Dim strBookmark        As String
 
    lDocNo = AddDocNo(ID)
    strCriteria = "fLocID = " & ID & " AND DocNo = " & lDocNo
 
    If DCount("ItemID", "tblItems", strCriteria) = 0 Then
           strSql = StringFormatSQL("INSERT INTO tblItems (fLocID, DocNo, ITPath, Item, InUse)" & _
                    " values ({0}, {1}, {2}, '(New)', True);", _
                    ID, lDocNo, strITPath)
      Else
          strSql = StringFormatSQL("UPDATE tblItems" & _
                                " SET ITPath = {0}," & _
                                " Item = '(New)'," & _
                                " InUse = True" & _
                                " WHERE flocID = {1} and" & _
                                " DocNo = {2};", _
                                strITPath, ID, lDocNo)
    End If
SQLExecute (strSql)
Set rst = Me.RecordsetClone
    strBookmark = rst.Bookmark  'isn't in recordset before requery (no current record)
    Me.Requery
    Me.Bookmark = strBookmark
 Set rst = Nothing
End Sub 
	 
 
		 
 
		 
 
		