Page 2 of 2 FirstFirst 12
Results 16 to 28 of 28
  1. #16
    2 Star Lounger
    Join Date
    Mar 2003
    Posts
    191
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MonthView Control (VB6)

    Hans,
    I was wondering why you suggest that having 40 date picker fields may not be a good idea? It was the only way I could think of to solve my problem. I short, the aim of my application is for users to be able to send the information of their requested travel bookings to their travel agent. There is a need for at least 10 flight requests and 5 hotel and car bookings.
    If there is an easier way I would be greatful of any advice.
    I had previously tried to do a similiar thing using a Custom Form in Outlook but users found using Outlook a little difficult (believe it or not!).
    Thanks heaps for your time.

    Bill

  2. #17
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: MonthView Control (VB6)

    Bill,

    It seems to me that one form with space for 10 flight requests, 5 hotel bookings and 5 car bookings with details for each will be rather cluttered. I haven't thought deeply about it, but I would probably create a form that presents a non-editable overview of the customer's bookings, with command buttons that show a popup form for editing an existing booking or adding a new one.

  3. #18
    2 Star Lounger
    Join Date
    Mar 2003
    Posts
    191
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MonthView Control (VB6)

    Hans,
    The code you kindly provided works up to a point. It blanks out all the fields as required and allows the date picker to be selected, however when I select the date, the field goes back to being blank. I had a go at solving the problem myself with some limited success.
    The code at the end of this message, when added to the code you provided, enables the field to retain the date when it is selected from the date picker field. However it only works for one field (dtpDepDate1).
    I don't really want to write the same code 40 times for the 40 fields that will have to be changed. Is there an easier way of doing this?
    On the other issue of why so many fields, I have attached a screen shot which may offer a better explanation than I was able to offer.
    Thanks as always.

    Bill

    Private Sub dtpDepDate1_CloseUp()
    FormatDTPicker
    End Sub

    Private Sub dtpDepDate1_Format(ByVal CallbackField As String, _
    FormattedString As String)
    If CallbackField = "X" Then
    FormattedString = ""
    End If
    End Sub

    Private Sub FormatDTPicker()
    With dtpDepDate1
    If .Value = vbNull Then
    .Format = dtpCustom
    .CustomFormat = "X"
    Else
    .Format = dtpShortDate
    End If
    End With
    End Sub

    Private Sub dtpDepDate1_MouseDown(Button As Integer, _
    Shift As Integer, X As Single, Y As Single)
    With dtpDepDate1
    If .Value = vbNull Then
    .Value = Now
    End If
    End With

  4. #19
    2 Star Lounger
    Join Date
    Mar 2003
    Posts
    191
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MonthView Control (VB6)

    Oops, sorry the attachment didn't make it last time. Another try.

  5. #20
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: MonthView Control (VB6)

    Hi Bill,

    I didn't know that you had organized your form with a tab control; it looks good, I admit.

    About the code: the Date/Time picker is not installed on the PC I'm using at the moment (neither is VB6), so I can't test code. You should be able to reduce the code for each of the events to one line, calling a generalized routine:

    Private Sub dtpDepDate1_CloseUp()
    FormatDTPicker 1
    End Sub

    Private Sub FormatDTPicker(i As Integer)
    With Me.Controls("dtpDepDate"& i)
    If .Value = vbNull Then
    .Format = dtpCustom
    .CustomFormat = "X"
    Else
    .Format = dtpShortDate
    End If
    End With
    End Sub

    Private Sub dtpDepDate1_Format(ByVal CallbackField As String, FormattedString As String)
    HandleFormat
    End Sub

    Private Sub HandleFormat(ByVal CallBackField As String, FormattedString As String)
    If CallbackField = "X" Then
    FormattedString = ""
    End If
    End Sub

    Private Sub dtpDepDate1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    HandleMouseDown 1
    End Sub

    Private Sub HandleMouseDown(i As Integer)
    With Me.Controls("dtpDepDate" & i)
    If .Value = vbNull Then
    .Value = Now
    End If
    End With
    End Sub

    Another remark: have you tried to use control arrays?

  6. #21
    2 Star Lounger
    Join Date
    Mar 2003
    Posts
    191
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MonthView Control (VB6)

    Hans,
    Thanks for that. I am away from my normal PC at the moment so I won't be able to test your code until tomorrow. I will let you know how I go.
    As for control arrays, I must admit I have read a bit about them but have the confidence to use them. Is it in my interests to do so?
    Appreciate your help.

    Bill

  7. #22
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: MonthView Control (VB6)

    Bill,

    Instead of independent controls dtpDepDate1 to dtpDepDate10, you could have 10 controls all named dtpDepDate, with index 1 through 10. The controls in a control array share event procedures, so you don't have to write 10 individual routines for each event.

  8. #23
    2 Star Lounger
    Join Date
    Mar 2003
    Posts
    191
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MonthView Control (VB6)

    Hans - Your explanation is much clearer than the books I have been reading. I understand now and will look at it. Thanks heaps.

    Bill

  9. #24
    2 Star Lounger
    Join Date
    Mar 2003
    Posts
    191
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MonthView Control (VB6)

    Hi Hans,
    I have installed the code and still no go:-( The date picker field works for field dtpDepDate1 as it is supposed to but for the remaining fields the field does not retain the value once selected.
    I have taken the liberty of attaching all of the code as it now exists to see if you can see where the problem is. I have looked without success.
    Thanks heaps for your time.

    Bill

    Option Explicit
    Private Sub Form_Load()
    Dim i As Integer
    For i = 1 To 10
    Me.Controls("dtpArrDate" & i).Format = dtpCustom
    Me.Controls("dtpArrDate" & i).CustomFormat = " ' "
    Me.Controls("dtpDepDate" & i).Format = dtpCustom
    Me.Controls("dtpDepDate" & i).CustomFormat = " ' "
    Next i
    For i = 1 To 5
    Me.Controls("dtpCheckInDate" & i).Format = dtpCustom
    Me.Controls("dtpCheckInDate" & i).CustomFormat = " ' "
    Me.Controls("dtpCheckOutDate" & i).Format = dtpCustom
    Me.Controls("dtpCheckOutDate" & i).CustomFormat = " ' "
    Me.Controls("dtpCarPickUp" & i).Format = dtpCustom
    Me.Controls("dtpCarPickUp" & i).CustomFormat = " ' "
    Me.Controls("dtpCarDropOff" & i).Format = dtpCustom
    Me.Controls("dtpCarDropOff" & i).CustomFormat = " ' "
    Next i
    End Sub
    Private Sub dtpDepDate1_CloseUp()
    FormatDTPicker 1
    End Sub

    Private Sub FormatDTPicker(i As Integer)
    With Me.Controls("dtpDepDate" & i)
    If .Value = vbNull Then
    .Format = dtpCustom
    .CustomFormat = "X"
    Else
    .Format = dtpShortDate
    End If
    End With
    End Sub

    Private Sub dtpDepDate1_Format(ByVal CallBackField As String, FormattedString As String)
    HandleFormat
    End Sub

    Private Sub HandleFormat(ByVal CallBackField As String, FormattedString As String)
    If CallBackField = "X" Then
    FormattedString = ""
    End If
    End Sub

    Private Sub dtpDepDate1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    HandleMouseDown 1
    End Sub

    Private Sub HandleMouseDown(i As Integer)
    With Me.Controls("dtpDepDate" & i)
    If .Value = vbNull Then
    .Value = Now
    End If
    End With
    End Sub

  10. #25
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: MonthView Control (VB6)

    You will have to create on-line event procedures for the others too. You just have

    Private Sub dtpDepDate1_CloseUp()
    FormatDTPicker 1
    End Sub

    now, you should also create

    Private Sub dtpDepDate2_CloseUp()
    FormatDTPicker 2
    End Sub

    through

    Private Sub dtpDepDate10_CloseUp()
    FormatDTPicker 10
    End Sub

    Similarly

    Private Sub dtpDepDate2_Format(ByVal CallBackField As String, FormattedString As String)
    HandleFormat
    End Sub

    through

    Private Sub dtpDepDate10_Format(ByVal CallBackField As String, FormattedString As String)
    HandleFormat
    End Sub

    and

    Private Sub dtpDepDate2_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    HandleMouseDown 2
    End Sub

    through

    Private Sub dtpDepDate10_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    HandleMouseDown 10
    End Sub

    You see that you still need to create event handlers for all controls, but you don't have to copy multiple lines of code into each, you just call a common routine. If you were to use control arrays, this wouldn't be necessary. As I wrote, the items in a control array use shared event handlers.

  11. #26
    2 Star Lounger
    Join Date
    Mar 2003
    Posts
    191
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MonthView Control (VB6)

    Hans,
    So far, so good. The code works fine for the dtpDepDate fields. I tried to adapt the code for the remaining fields one by one and the code continually stops in the first line of the following code: I get an ambigous name detected message.

    Private Sub FormatDTPicker(i As Integer)
    With Me.Controls("dtpArrDate" & i)
    If .Value = vbNull Then
    .Format = dtpCustom
    .CustomFormat = "X"
    Else
    .Format = dtpShortDate
    End If
    End With
    End Sub

    As this thread is getting a little long I have attached the whole code as it currently is as a .txt file to this message.
    Thanks heaps.

    Bill

  12. #27
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 18 Times in 18 Posts

    Re: MonthView Control (VB6)

    Bill,

    You asked the same question in <post#=269268>post 269268</post#>, so you'll get the same answer: <post#=269403>post 269403</post#>.

  13. #28
    2 Star Lounger
    Join Date
    Mar 2003
    Posts
    191
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: MonthView Control (VB6)

    Hans - Arh, that makes sense to me now. Thanks.

    Bill

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •