|
-
Feb 9th, 2006, 12:02 PM
#1
Thread Starter
Lively Member
[RESOLVED] Selecting data for extraction
I have put together this excel form for collecting data which is working well. What I now want is to have a way of selecting a starting and ending date for the dates of the data I want to extract from the data list, to an external workbook.I want to do this from another form, maybe by using a date picker method. I have attached the file, there are 2 passwords, "getmein" will open the workbook and "start" will open the form. I am a total newbie and this will be a great help as I have no idea where to start.
Thanks
-
Feb 9th, 2006, 12:22 PM
#2
Re: Selecting data for extraction
Try the following. The Test procedure is just to show you the main ExportData procedure in action.
VB Code:
Option Explicit
Sub Test()
ExportData "12/01/2005", "12/31/2005"
End Sub
Sub ExportData(dStartDate As Date, dEndDate As Date)
Dim wksDataSheet As Worksheet
Dim wkbExport As Workbook
'The worksheet to be exported
Set wksDataSheet = Worksheets("IquaDB")
'Turn off any existing filters
wksDataSheet.AutoFilterMode = False
'Filter the data based on the passed date parameters
wksDataSheet.Range("A1").AutoFilter _
field:=1, _
Criteria1:=">=" & dStartDate, _
Operator:=xlAnd, _
Criteria2:="<=" & dEndDate
'Add a new workbook
Set wkbExport = Application.Workbooks.Add
'Copy the data to the new book
wksDataSheet.Range("A:J").Copy Destination:=wkbExport.Worksheets(1).Range("A1")
'Clear the clipboard
Application.CutCopyMode = False
'Turn the filters off
wksDataSheet.AutoFilterMode = False
'Clear the object variables
Set wksDataSheet = Nothing
Set wkbExport = Nothing
End Sub
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Feb 10th, 2006, 06:42 AM
#3
Thread Starter
Lively Member
Re: Selecting data for extraction
Excellent Dkenny
What I have done is created a couple of date pickers to select the dates from a form but its not quite working.
Code:
Private Sub cmdOk2_Click()
Dim dStartDate As Date
Dim dEndDate As Date
dStartDate = dpStart()
dEndDate = dpEnd()
ExportData dStartDate, dEndDate
End Sub
The date pickers have got there day and month format back to front. Can I tell it to use dd/mm/yyyy format instead??
Last edited by thelocaluk; Feb 10th, 2006 at 07:04 AM.
-
Feb 10th, 2006, 08:52 AM
#4
Re: Selecting data for extraction
Change the datatype on dStartDate and dEndDate to Long.
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Feb 10th, 2006, 09:14 AM
#5
Thread Starter
Lively Member
Re: Selecting data for extraction
 Originally Posted by DKenny
Change the datatype on dStartDate and dEndDate to Long.
Sorry to be a bit thick
How do I do that?
-
Feb 10th, 2006, 09:15 AM
#6
Re: Selecting data for extraction
VB Code:
Private Sub cmdOk2_Click()
Dim dStartDate As Long
Dim dEndDate As Long
dStartDate = dpStart()
dEndDate = dpEnd()
ExportData dStartDate, dEndDate
End Sub
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Feb 10th, 2006, 09:44 AM
#7
Thread Starter
Lively Member
Re: Selecting data for extraction
Did that, but it now come ups with a ByRef argument type mismatch at the ExportData line.
-
Feb 10th, 2006, 10:01 AM
#8
Re: Selecting data for extraction
try changing
Sub ExportData(dStartDate As Date, dEndDate As Date)
to
Sub ExportData(ByVal dStartDate As Date, ByVal dEndDate As Date)
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Feb 10th, 2006, 10:10 AM
#9
Thread Starter
Lively Member
Re: Selecting data for extraction
Hey DKenny, I changed the
Sub ExportData(dStartDate As Date, dEndDate As Date)
to
Sub ExportData(dStartDate As Long, dEndDate As Long)
and that seems to be working just great.
Your an absolute guru, many thanks for all your help.
P.S I've read many post here as a keen newbie to VB and often come across your name. Keep up the good work, its a great help to people like me.
-
Feb 10th, 2006, 10:11 AM
#10
Re: Selecting data for extraction
Thanks, glad I could help.
Don't forget to mark your post as resloved
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|