Vanguard
06-02-2016, 10:59 PM
Hi again,
I've got another problem that has been illuding me for a while now. It happens when I try and open excel from access. The first time it works like a charm but after closing excel the excel process still runs in the background. When I run the macro again excel flashes on the screen quickly and disappears, the process still running in the task manager.
Has anyone else had this problem before or know of how I might fix it?
Private Sub Command181_Click()
'Opens drawing register and updates values
Dim ApXL As Object
Dim xlWB As Object
Dim xlWS As Object
Dim ProjectNumber As String
Dim ProjectName As String
Dim Year As String
Dim Prefix As String
'Lookup and set variables from access record for job number.
ProjectNumber = DLookup("[Job Number]", "ProjectT", "[Job Number] = [Forms].[Projects Explorer].[Job Number]")
ProjectName = DLookup("[Project Name]", "ProjectT", "[Job Number] = [Forms].[Projects Explorer].[Job Number]")
FirstName = DLookup("[First Name]", "ClientsT", "[ClientID] = [Forms].[Projects Explorer].[Client]")
LastName = DLookup("[Last name]", "ClientsT", "[ClientID] = [Forms].[Projects Explorer].[Client]")
Company = DLookup("[Company Name]", "ClientsT", "[ClientID] = [Forms].[Projects Explorer].[Client]")
StreetAddress = DLookup("[StreetAddress]", "ClientsT", "[ClientID] = [Forms].[Projects Explorer].[Client]")
Suburbvar = DLookup("[Suburb]", "ClientsT", "[ClientID] = [Forms].[Projects Explorer].[Client]")
Statevar = DLookup("[State]", "ClientsT", "[ClientID] = [Forms].[Projects Explorer].[Client]")
PostCode = DLookup("[PostCode]", "ClientsT", "[ClientID] = [Forms].[Projects Explorer].[Client]")
'Obtain year from job number code.
If Len(ProjectNumber) = 5 Then
Prefix = Left(ProjectNumber, 2)
Year = "20" & Prefix
Else
Prefix = Left(ProjectNumber, 1)
Year = "200" & Prefix
End If
'Open .xls file for pre macro job numbers.
If ProjectNumber <= 14072 Then
Set ApXL = CreateObject("Excel.Application")
Set xlWB = Workbooks.Open("E:\Data\jobfiles\" & Year & "\" & ProjectNumber & "\Standard Forms\" & ProjectNumber & " Drawing Register.xls")
ApXL.Visible = True
'Open .xlxm file for post marco job mumbers.
Else
Set ApXL = CreateObject("Excel.Application")
Set xlWB = Workbooks.Open("E:\Data\jobfiles\" & Year & "\" & ProjectNumber & "\Standard Forms\" & ProjectNumber & " Drawing Register.xlsm")
ApXL.Visible = True
Set xlWS = xlWB.Worksheets("Sheet1")
xlWS.Activate
rspCreate = MsgBox("Would You like to import project specific information from the projects database?", 65540, "ASD Projects Database")
If rspCreate = vbYes Then
'Project name
xlWS.Range("D4").Value = [ProjectName]
'Project nunber
xlWS.Range("D5").Value = [ProjectNumber]
'Client name & address line 1
xlWS.Range("B54").Value = [Company] & " " & [FirstName] & " " & [LastName]
'Client name & address line 2
xlWS.Range("D54").Value = [StreetAddress] & " " & [Suburbvar] & " " & [Statevar] & " " & [PostCode]
'Attn name
xlWS.Range("D56").Value = [FirstName] & " " & [LastName]
End If
ApXL.Visible = True
End If
Set xlWS = Nothing
Set x1WB = Nothing
Set ApXL = Nothing
End Sub
I've got another problem that has been illuding me for a while now. It happens when I try and open excel from access. The first time it works like a charm but after closing excel the excel process still runs in the background. When I run the macro again excel flashes on the screen quickly and disappears, the process still running in the task manager.
Has anyone else had this problem before or know of how I might fix it?
Private Sub Command181_Click()
'Opens drawing register and updates values
Dim ApXL As Object
Dim xlWB As Object
Dim xlWS As Object
Dim ProjectNumber As String
Dim ProjectName As String
Dim Year As String
Dim Prefix As String
'Lookup and set variables from access record for job number.
ProjectNumber = DLookup("[Job Number]", "ProjectT", "[Job Number] = [Forms].[Projects Explorer].[Job Number]")
ProjectName = DLookup("[Project Name]", "ProjectT", "[Job Number] = [Forms].[Projects Explorer].[Job Number]")
FirstName = DLookup("[First Name]", "ClientsT", "[ClientID] = [Forms].[Projects Explorer].[Client]")
LastName = DLookup("[Last name]", "ClientsT", "[ClientID] = [Forms].[Projects Explorer].[Client]")
Company = DLookup("[Company Name]", "ClientsT", "[ClientID] = [Forms].[Projects Explorer].[Client]")
StreetAddress = DLookup("[StreetAddress]", "ClientsT", "[ClientID] = [Forms].[Projects Explorer].[Client]")
Suburbvar = DLookup("[Suburb]", "ClientsT", "[ClientID] = [Forms].[Projects Explorer].[Client]")
Statevar = DLookup("[State]", "ClientsT", "[ClientID] = [Forms].[Projects Explorer].[Client]")
PostCode = DLookup("[PostCode]", "ClientsT", "[ClientID] = [Forms].[Projects Explorer].[Client]")
'Obtain year from job number code.
If Len(ProjectNumber) = 5 Then
Prefix = Left(ProjectNumber, 2)
Year = "20" & Prefix
Else
Prefix = Left(ProjectNumber, 1)
Year = "200" & Prefix
End If
'Open .xls file for pre macro job numbers.
If ProjectNumber <= 14072 Then
Set ApXL = CreateObject("Excel.Application")
Set xlWB = Workbooks.Open("E:\Data\jobfiles\" & Year & "\" & ProjectNumber & "\Standard Forms\" & ProjectNumber & " Drawing Register.xls")
ApXL.Visible = True
'Open .xlxm file for post marco job mumbers.
Else
Set ApXL = CreateObject("Excel.Application")
Set xlWB = Workbooks.Open("E:\Data\jobfiles\" & Year & "\" & ProjectNumber & "\Standard Forms\" & ProjectNumber & " Drawing Register.xlsm")
ApXL.Visible = True
Set xlWS = xlWB.Worksheets("Sheet1")
xlWS.Activate
rspCreate = MsgBox("Would You like to import project specific information from the projects database?", 65540, "ASD Projects Database")
If rspCreate = vbYes Then
'Project name
xlWS.Range("D4").Value = [ProjectName]
'Project nunber
xlWS.Range("D5").Value = [ProjectNumber]
'Client name & address line 1
xlWS.Range("B54").Value = [Company] & " " & [FirstName] & " " & [LastName]
'Client name & address line 2
xlWS.Range("D54").Value = [StreetAddress] & " " & [Suburbvar] & " " & [Statevar] & " " & [PostCode]
'Attn name
xlWS.Range("D56").Value = [FirstName] & " " & [LastName]
End If
ApXL.Visible = True
End If
Set xlWS = Nothing
Set x1WB = Nothing
Set ApXL = Nothing
End Sub