Results 1 to 10 of 10
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Serbia and Montenegro (Yugoslavia)
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Pass in Values when Opening a New Form (VB6)

    I have a primary form for which I've created a search routine for. When the search yields multiple returns, I want to open a new form that displays line item information about each duplicate, have the user select one, then recall that record in the primary form.

    I'm stuck on the first step of this: How do I pass in the recordset from the primary form to the duplicate display form? (all the duplicate form will be is basically a listview displaying an index number, name, and date of birth).

  2. #2
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Pass in Values when Opening a New Form (VB6)

    Let's see, if the recordset is declared in the declaration section of a module, then any form can access the recordset. Right?

    Or, declare the recordset Public at any code level. If you do that in the primary form, closing the form will kill the recordset, so either hide the primary before displaying the "duplicates" form or see paragraph 1.

    Gee, I hope that helps. Maybe a post to the Access forum would fetch a response too.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Pass in Values when Opening a New Form (VB6)

    Do you want the same recordset in another form? Or do you only want the search results in the second form? Have you tried using the SQL that you built for your search to set the recordsource property of the second form? How you do it depends on how you bind the recordset to the form, but that's where I would start.
    Charlotte

  4. #4
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Serbia and Montenegro (Yugoslavia)
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Pass in Values when Opening a New Form (VB6)

    Thanks, Kevin and Charlotte.

    I only need the search results in the second form. I've created a function that returns a disconnected ADO recordset using an SQL string as a parameter, which I use for most everything in my app. The WHERE portion of the passed in SQL statement is based on values on the main form. Until I created this search feature it was a simple thing in just grabbing the key field. Opening up the search to any combinations of fields I had to dynamically build the WHERE clause, like you helped me with the control loop and the Select Case statement. But I need the values from the main form to complete the SQL statement so it can't be re-run in the lookup form.

    I did dimension a global ADODB.Recordset in a public module to get by for now which is one way of getting the information to the lookup form. As I learn VB I'm doing my best to try and build good habits, and using a public module rather than passing the recordset directly to the new form seemed like it might be sloppy. But, from what I'm gathering, that is the way these things are transported in this version. I guess I was looking for a type of constructor for a form, if that makes sense.

    The process I'm envisioning is that the user would do a search on the primary form, when multiple records are returned it will pass the resulting recordset to a public module and launch the new form that will take the rs from the module and populate a ListView control. When the user selects which record they want to see, I would persist the selected record's key field value back to the main form via the module.

    Mike

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Pass in Values when Opening a New Form (VB6)

    It sounds like you're thinking of a VB equivalent of the recordset property in Access forms, which doesn't exist, of course. Global variables are used more widely in VB than in Access because they work better in VB.

    Are you talking about a listbox or a custom control? With a listbox, you could create a callback function to populate the listbox using the global recordset. I'm not familiar with a ListView control. In either case, though, you could wrap all the ugly details in a List class and pass the "global" recordset into that class as an object argument. One of the methods of that class could populate the listview you bind to it.
    Charlotte

  6. #6
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Serbia and Montenegro (Yugoslavia)
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Pass in Values when Opening a New Form (VB6)

    I just created a global recordset variable to use as a medium to pass the data between the forms. It is working great.

    I did some checking and I think ListView is a custom control. It is definitely not a ListBox, and the ListView is a little easier to use.

    I am stuck on something with it that I'm hoping that you can help me (hoping because I'm sure it is a non-standard control. I got everything working including when you click on the column headers to sort the field. It works on the index number in the first column, also works correctly on the Patient Name column, but it is sorting the DOB as if it were a text field. I've stepped through the code and did a TypeName() in the debug window on the recordset item that populates that field and I've confirmed it is of Date datatype. I'm not sure why it isn't working. I'm posting the code for the event and a sub I'm using to sort the columns:

    Private Sub Form_Load()

    Dim Itm As ListItem


    With lvwDupes

    ' .ColumnHeaders.Clear

    lvwDupes.ColumnHeaders. _
    Add , , "MR Number", 1160
    lvwDupes.ColumnHeaders. _
    Add , , "Patient Name", 3400
    lvwDupes.ColumnHeaders. _
    Add , , "Birthdate", 1125

    Do While Not gRS.EOF

    Set Itm = .ListItems.Add(, , gRS(cmMRNumber) & vbNullString)
    Itm.SubItems(1) = gRS(cmLastName) & ", " & gRS(cmFirstName) & vbNullString
    Itm.SubItems(2) = gRS(cmdob) & vbNullString

    gRS.MoveNext
    Loop
    End With


    Screen.MousePointer = vbNormal




    End Sub

    Public Sub ListView_SortColumn(lvw As ListView, Index As Integer)



    ' When a ColumnHeader object is clicked, the ListView control
    ' is sorted by the subitems of that column.

    For X = 1 To lvw.ColumnHeaders.Count

    ' If Not X = Index + 1 Then
    If Left$(lvw.ColumnHeaders(X).Text, 1) = ">" Or _
    Left$(lvw.ColumnHeaders(X).Text, 1) = "<" Then
    lvw.ColumnHeaders(X).Text = Mid$(lvw.ColumnHeaders(X).Text, 2)
    End If
    ' End If

    Next X


    Debug.Print lvw.ColumnHeaders.Item(Index + 1).Text
    With lvw
    If .SortKey = Index Then
    ' Toggle the sort order
    .SortOrder = Abs(.SortOrder - 1)

    If .SortOrder = lvwDescending Then
    lvw.ColumnHeaders.Item(Index + 1).Text = "<" & lvw.ColumnHeaders.Item(Index + 1)
    Else
    lvw.ColumnHeaders.Item(Index + 1).Text = ">" & lvw.ColumnHeaders.Item(Index + 1)
    End If


    Else
    .SortOrder = lvwAscending
    lvw.ColumnHeaders.Item(Index + 1).Text = ">" & lvw.ColumnHeaders.Item(Index + 1)
    End If

    ' Set the SortKey to the Index of the ColumnHeader - 1
    .SortKey = Index

    ' Set Sorted to True to sort the list
    .Sorted = True
    End With

    End Sub

  7. #7
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Pass in Values when Opening a New Form (VB6)

    If it works like a listbox, the date is being sorted as a string because that's what it is in the listview regardless of the datatype You may have to use a conversion function to get it to sort in date order.
    Charlotte

  8. #8
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Serbia and Montenegro (Yugoslavia)
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Pass in Values when Opening a New Form (VB6)

    If you mean using the CDate() function at the point it is populating SubItem(2), I've tried that. What's also interesting is that the MRNumber column is of number datatype and it sorts just fine.

  9. #9
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Serbia and Montenegro (Yugoslavia)
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Pass in Values when Opening a New Form (VB6)

    BTW, It appears that ListView is part of standard VB. I copied the following from the help file:

    Distribution Note The ListView control is part of a group of ActiveX controls that are found in the MSCOMCTL.OCX file. To use the ListView control in your application, you must add the MSCOMCTL.OCX file to the project. When distributing your application, install the MSCOMCTL.OCX file in the user's Microsoft Windows System or System32 directory. For more information on how to add an ActiveX control to a Visual Basic project, see the Visual Basic Programmer's Guide.

    It's been a nice control to work with, until now. . [img]/forums/images/smilies/sad.gif[/img]

  10. #10
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    Serbia and Montenegro (Yugoslavia)
    Posts
    342
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Pass in Values when Opening a New Form (VB6)

    This is interesting (and frustrating). The help file clearly states that it will sort by date. I used the CDate() function when assigning the value to Itm.Subitems(2). In the line right after I'm doing a Debug.Print TypeOf(itm.subitems(2), for which it returns "String".

    I will call Microsoft and post their response here.

Posting Permissions

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