Module code

lewy the fly

New Member
Joined
Mar 6, 2011
Messages
5
I have the following module used to import data from a access data base, however I only want it to work if the C9 is equal to zero. can any one help with the required code.

Sub Insert_Data()
'
' Insert_Data Macro
' Insert Data from Cabnet Vision Macro recorded 12/09/2004 by Lewis
'
' Keyboard Shortcut: Ctrl+i
'
With ActiveSheet.QueryTables.Add(Connection:=Array(Array( _
"ODBC;DSN=MS Access Database;DBQ=C:\Planit\Solid_5_0\Database\db1.mdb;DefaultDir=C:\Planit\Solid_5_0\Database;DriverId=25;FIL=M" _
), Array("S Access;MaxBufferSize=2048;PageTimeout=5;")), Destination:=Range( _
"Q3"))
.CommandText = Array( _
"SELECT `Parts Query`.`Cabinet ID`, `Parts Query`.`Width String`, `Parts Query`.`Length String`, `Parts Query`.Description, `Parts Query`.Name, `Parts Query`.Typ" _
, "e" & Chr(13) & "" & Chr(10) & "FROM `C:\Planit\Solid_5_0\Database\db1`.`Parts Query` `Parts Query`")
.Name = "Query from MS Access Database_4"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
With ActiveSheet.QueryTables.Add(Connection:=Array(Array( _
"ODBC;DSN=MS Access Database;DBQ=C:\Planit\users\administrator\REPORT.MDB;DefaultDir=C:\CabinetVision\Solid\Database;DriverId=281;F" _
), Array("IL=MS Access;MaxBufferSize=2048;PageTimeout=5;")), Destination:= _
Range("B65"))
.CommandText = Array( _
"SELECT `Job Info`.`Job Number`" & Chr(13) & "" & Chr(10) & "FROM `C:\Planit\users\administrator\REPORT`.`Job Info` `Job Info`" _
)
.Name = "Query from MS Access Database_19"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = True
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.Refresh BackgroundQuery:=False
Call FilterMaterials
End With
End With
End Sub


Regards Lewy
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Stick this before the first executable statement in the module:-
Code:
if activesheet.range("c9").value<>0 then exit sub
(Untested but fairly confident.)

Please remember to post your code between CODE tags in future - the # icon in the editor toolbar.
 
Upvote 0

Forum statistics

Threads
1,224,513
Messages
6,179,212
Members
452,895
Latest member
BILLING GUY

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top