Solved

how do i define variable Date in Visual Basic?

Posted on 2014-08-01
7
226 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
7 Comments
 
LVL 4

Expert Comment

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

DateTime.Parse Method
0
 
LVL 34

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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 34

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 34

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

737 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