Share via

VBA Code

Anonymous
2016-05-16T08:54:29+00:00

I am using VBA Code: in that I need to take users input in below format:

'06-May-16'  and '11-May-16'

(every time users input will be different)

because in VBA, we are going to fire SQL which will have below condition: 

AND TRUNC (start_time) BETWEEN  '06-May-16' AND '11-May-16' ( users input should come here directly)

but I am not getting any way, please help me with this.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2016-05-16T12:43:50+00:00

The link in the post works for me, however you can get it from http://www.gmayor.com/Forum/CalendarForm v1.5.2.xlsm

Was this answer helpful?

0 comments No comments

Answer accepted by question author

Anonymous
2016-05-16T12:24:32+00:00

Hi,

try and this...

Dim Date1 As Long, Date2 As Long

Dim sDate1 As String, sDate2 As String

Date1 = DateSerial(2016, 5, 6)

Date2 = DateSerial(2016, 5, 11)

sDate1 = Format(Date1, "dd-mmm-yy")

sDate2 = Format(Date2, "dd-mmm-yy")

Was this answer helpful?

0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Anonymous
    2016-05-16T12:22:52+00:00

    please help on same

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2016-05-16T09:56:55+00:00

    hi http://bit.ly/1ossyMA. this link is not opening

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2016-05-16T09:13:24+00:00

    I would be inclined to create a simple userform with two text fields to collect the two dates with a date picker - I particularly like Trevor Eyre's VBA date picker - http://bit.ly/1ossyMA. You can easily format the output of the two date text boxes to give you the format you require for your SQL string e.g. something like

    strDate1 = Format(TextBox1.Text, "'dd-mmm-yy'")

    strDate1 = Format(TextBox2.Text, "'dd-mmm-yy'")

    AND TRUNC (start_time) BETWEEN  " & strDate1 & " AND " & strDate2

    or don't even bother with the userform and call the date picker directly from your code e.g. using Trevor's code

    Dim strDate1 As String, strDate2 As String

        strDate1 = Format(BasicCalendar(Date), "'dd-mmm-yy'")

        strDate2 = Format(BasicCalendar(Date), "'dd-mmm-yy'")

    Was this answer helpful?

    0 comments No comments