Hi,
I might be tired by now and it just started to be very annoying.
I have a form frmAddNewProject that is a Data Entry form.
When you click Add Project on the form, it creates folders and copies files to a location and also creates new record(s) in the ProjectT table with apriopriate information.
Here is my code:
Everything works fine till here.
Now I would like to close the form but closing it gives me an additional empty record.
I tried this:
to remove all values, but then it just adds an empty record.
Is there a way to close that form without removing my legitimate new records and without adding empty ones?
Please help
I might be tired by now and it just started to be very annoying.
I have a form frmAddNewProject that is a Data Entry form.
When you click Add Project on the form, it creates folders and copies files to a location and also creates new record(s) in the ProjectT table with apriopriate information.
Here is my code:
Code:
Private Sub cmdAdd_Click()
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
Dim FolderPath As String
Dim strType As String
Dim strYear As String
Dim strGPN As String
Dim strDesc As String
Dim intComp As Integer
Dim i As Integer
Dim rstProject As DAO.Recordset
Dim dbsProjectBoard As DAO.Database
strYear = DatePart("yyyy", Date)
strGPN = Left([GPNnumber], 2) & "-" & Right([GPNnumber], 4)
strDesc = Me.ProjectDescription
strType = DLookup("[Abbr]", "ProjectTypeT", "[ProjectTypeID] = " & Me.ProjectType)
intComp = CInt(txtComponents)
If intComp = 1 Then
ToPath = "P:\APQP NPD Projects\" & strType & "\" & strYear & "\" & strGPN & " - " & strDesc
FromPath = "P:\xDocuments\Templates\Project Template - Copy"
If Right(FromPath, 1) = "\" Then
FromPath = Left(FromPath, Len(FromPath) - 1)
End If
If Right(ToPath, 1) = "\" Then
ToPath = Left(ToPath, Len(ToPath) - 1)
End If
Set FSO = CreateObject("scripting.filesystemobject")
If FSO.FolderExists(FromPath) = False Then
MsgBox FromPath & " doesn't exist"
Exit Sub
End If
FSO.CopyFolder Source:=FromPath, Destination:=ToPath
Set FSO = Nothing
MsgBox "destination path is: " & ToPath
Set dbsProjectBoard = CurrentDb
Set rstProject = CurrentDb.OpenRecordset("ProjectT")
rstProject.AddNew
rstProject!Status = Me.Status
rstProject!ProjectType = Me.ProjectType
rstProject!GPNnumber = Me.GPNnumber
rstProject!ProjectDescription = Me.ProjectDescription
rstProject!Customer = Me.Customer
rstProject!ProjectLead = Me.ProjectLead
rstProject!LeadBDM = Me.LeadBDM
rstProject!PotentialValuePA = Me.PotentialValuePA
rstProject!Folder = ToPath
rstProject!Component = "01"
rstProject.Update
rstProject.Close
Set rstProject = Nothing
End If
If intComp > 1 Then
FromPath = "P:\xDocuments\Templates\Project Template - Copy"
FolderPath = "P:\APQP NPD Projects\" & strType & "\" & strYear & "\" & strGPN & " - " & strDesc
Set FSO = CreateObject("scripting.filesystemobject")
If FSO.FolderExists(FolderPath) = False Then
FSO.CreateFolder FolderPath
End If
Set FSO = Nothing
For i = 1 To intComp
ToPath = "P:\APQP NPD Projects\" & strType & "\" & strYear & "\" & strGPN & " - " & strDesc & "\0" & i
Set FSO = CreateObject("scripting.filesystemobject")
If Right(FromPath, 1) = "\" Then
FromPath = Left(FromPath, Len(FromPath) - 1)
End If
If Right(ToPath, 1) = "\" Then
ToPath = Left(ToPath, Len(ToPath) - 1)
End If
If FSO.FolderExists(FromPath) = False Then
MsgBox FromPath & " doesn't exist"
Exit Sub
End If
FSO.CopyFolder Source:=FromPath, Destination:=ToPath
Set FSO = Nothing
MsgBox "destination path is: " & ToPath
Set dbsProjectBoard = CurrentDb
Set rstProject = CurrentDb.OpenRecordset("ProjectT")
rstProject.AddNew
rstProject!Status = Me.Status
rstProject!ProjectType = Me.ProjectType
rstProject!GPNnumber = Me.GPNnumber
rstProject!ProjectDescription = Me.ProjectDescription
rstProject!Customer = Me.Customer
rstProject!ProjectLead = Me.ProjectLead
rstProject!LeadBDM = Me.LeadBDM
rstProject!PotentialValuePA = Me.PotentialValuePA
rstProject!Folder = ToPath
rstProject!Component = "0" & i
rstProject.Update
rstProject.Close
Set rstProject = Nothing
Next i
End If
End Sub
Everything works fine till here.
Now I would like to close the form but closing it gives me an additional empty record.
I tried this:
Code:
Dim ctl As Control
On Error Resume Next
For Each ctl In Me.Controls
ctl = ctl.DefaultValue
Next
Set ctl = Nothing
to remove all values, but then it just adds an empty record.
Is there a way to close that form without removing my legitimate new records and without adding empty ones?
Please help