Solved

how do i define variable Date in Visual Basic?

Posted on 2014-08-01
7
218 Views
Last Modified: 2014-08-03
i have the following select statement:

Dim fpick&
Dim lpick&


" select invoiceno, invoicedate, sent_810, sent_211 as sent_mail from invheader where (sent_211 = 'N' or sent_211 is null) and (sent_810 = 'N' or sent_810 is null) and invoicedate between ? and ? "
  ' On Error GoTo UserError:
   fpick = InputBox("Select First Invoice# in Range")
    comm.Parameters(0) = fpick
   lpick = InputBox("Select Last Invoice# in Range")
    comm.Parameters(1) = lpick

i am receiving error when entering the date to message box
i know that the type is incorrect what should be the right type that the select will run fine with date?

thanks
gvilbis
0
Comment
Question by:gvilbis
  • 3
  • 2
7 Comments
 
LVL 4

Expert Comment

by:Chris Watson
ID: 40234192
DateTime.Parse(fpick)

DateTime.Parse Method
0
 
LVL 33

Accepted Solution

by:
ste5an earned 500 total points
ID: 40234194
First of all: VBScript or Visual Basic for Applications (VBA)?

As you mentioned Excel, I guess you mean VBA. Then it is simply Dim variableName AS Date. But interestingly, why do you pick numbers ??

Your code has more problems. InputBox returns only strings. You may use something like:
Dim instring as String
Dim fpick As Date
Dim lpick As Date

On Local Error Resume Next

instring = InputBox("Select First Invoice# in Range")
Err.Clear
fpick = CDate(instr)
If Err.Number <> 0 Then
  MsgBox "Cannot convert input to date."
End If

lpick = InputBox("Select Last Invoice# in Range")
Err.Clear
lpick = CDate(instr)
If Err.Number <> 0 Then
  MsgBox "Cannot convert input to date."
End If

On Local Error GoTo 0

comm.Parameters(0) = fpick
comm.Parameters(1) = lpick

Open in new window

0
 

Author Comment

by:gvilbis
ID: 40234233
its VBA i am not sure how to correct according the above, here is the code can you rewrite it?

Thanks

Dim fpick As Date
    Dim lpick As Date
    Dim conn As New Connection, rec As New Recordset
    Dim ws As Worksheet
    Dim comm As New Command


     Sheets("Invoice Mailed").Select
    Range("A2").Select
    Set ws = ThisWorkbook.Worksheets("Invoice Mailed")
    conn.Open "Provider=MSDASQL;DRIVER=SQL SERVER;SERVER=199.27.203.74,1433;DNS=wf10taa;UID=xx;PWD=xxxxx;DATABASE=MyDatabase"
    Set comm.ActiveConnection = conn
    comm.CommandText = _
    " select invoiceno, invoicedate, sent_810, sent_211 as sent_mail from invheader where (sent_211 = 'N' or sent_211 is null) and (sent_810 = 'N' or sent_810 is null) and invoicedate between ? and ? "
  ' On Error GoTo UserError:
   fpick = InputBox("Select First Invoice# in Range")
    comm.Parameters(0) = fpick
   lpick = InputBox("Select Last Invoice# in Range")
    comm.Parameters(1) = lpick
   
    rec.Open comm
   
    Sheets("Invoice Mailed").Select
    Range("A:Z").Clear
   
    ws.[A1].CopyFromRecordset rec
    rec.Close: conn.Close
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 33

Expert Comment

by:ste5an
ID: 40234286
CHANGE IMMEDIATLY YOU SQL SERVER CREDENTIALS !
0
 

Author Comment

by:gvilbis
ID: 40234367
I've requested that this question be deleted for the following reason:

not good question
0
 
LVL 33

Expert Comment

by:ste5an
ID: 40234348
CHANGE IMMEDIATLY YOU SQL SERVER CREDENTIALS !

CHANGE IMMEDIATLY YOU SQL SERVER CREDENTIALS !

CHANGE IMMEDIATLY YOU SQL SERVER CREDENTIALS !

Deleting the question is not sufficient
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question