'General Declarations
Declare Function SetFocusAPI Lib "user32" Alias "SetForegroundWindow" (ByVal hwnd As Long) As Long
Private Sub TestMakeNewTravelFolder_Click()
'Code by Daniel Pineault https://www.devhut.net/2018/08/26/access-vba-inserting-new-records/
'''''TODOLIST'''''
'1 Get New Travel Folder ID (TFID) from Hermes
'2 MkDir from TFID in H:\
'3 Mark category as DB logged (blue) and the new TFID to UserProperties
'4 Move to outlook folder hermes > new enquires
'5 Save msg to TF
'6 Save msg details to tbltravelfolderACTIONS
'7 Open frmTF_Enquiry
'''' MAKE SURE HERMES IS OPEN ''''
On Error GoTo Error_Handler
Dim appAccess As Object
Set appAccess = GetObject("C:\Hermes\DB\TEST_HermesFE.accdb")
If Err.Number <> 0 Then
'The database was not open so open it
Set appAccess = CreateObject("Access.Application")
Err.Clear
End If
'1 Get New TFID from Hermes
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("tblTravelFolder")
With rs
.AddNew
![CID] = "17794" 'Test value
.Update
End With
'' Need TFID back from Hermes to:-
' MkDir / Add New TFID to UserProperties
'2 MkDir from TFID in H:\
'''Need TFID from Hermes
'Dim strHermesTFID As String
' strHermesTFID = ???????
'Dim strTFName As String
'strTFName = "H:\TFID" & ("srtHermesTFID")
'If Len(Dir(strTFName, vbDirectory)) = 0 Then
' MkDir strTFName
'End If
'' Open folder to check again?
' Shell "C:\WINDOWS\explorer.exe """ & strTFName & "", vbNormalFocus
Error_Handler_Exit:
On Error Resume Next
If Not rs Is Nothing Then
rs.Close
Set rs = Nothing
End If
If Not db Is Nothing Then Set db = Nothing
Exit Sub
Error_Handler:
MsgBox "The following error has occurred" & vbCrLf & vbCrLf & _
"Error Number: " & Err.Number & vbCrLf & _
"Error Source: cmd_AddRec_Click" & vbCrLf & _
"Error Description: " & Err.Description & _
Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
, vbOKOnly + vbCritical, "An Error has Occurred!"
Resume Error_Handler_Exit
End Sub