Solved

pop up form on double click

Posted on 2007-03-22
19
196 Views
Last Modified: 2010-04-30
hello,

i need help in figuring out how to load a form with a double click.
When tthe user double clicks the row.  This will popup a new form, displaying the order number, client, item number and quantity in a “header”.

i.e

order:   order value
client:   client value
item:     item value

code inside a class builds the order details row:

strSql = ""
strSql = "proc_GetOrderDetails '" & m_strOrderNumber & "', '" & m_strClient & "', " & m_lngHighJumpToAgressoJobId
Set rstSelect = m_cnnAgresso.Execute(strSql)
 
' Loop through each detail record and add it to the history array.
If Not rstSelect Is Nothing Then
    If Not rstSelect.BOF Or Not rstSelect.EOF Then
        Do While Not rstSelect.EOF
            dblOrdered = CDbl(rstSelect![rev_val])
            dblReserved = CDbl(rstSelect![reserved_val])
            dblShipped = CDbl(rstSelect![vow_val])
            If m_strOrderType = "SO" Or m_strOrderType = "NW" Then
               ' This is a sales order.
               ' Add another row to the array
               intRecordCount = intRecordCount + 1
               ReDim Preserve p_vntSalesOrderDetails(8, intRecordCount)
               p_vntSalesOrderDetails(1, intRecordCount) = IIf(rstSelect![Level] = 1, rstSelect![line_no], "")
               p_vntSalesOrderDetails(2, intRecordCount) = IIf(rstSelect![Level] = 1, Trim(rstSelect![article]), "")
               p_vntSalesOrderDetails(3, intRecordCount) = IIf(rstSelect![Level] = 1, rstSelect![art_descr], Trim(rstSelect![physical_article]) + " - " + rstSelect![art_descr])
               p_vntSalesOrderDetails(4, intRecordCount) = rstSelect![rev_val]
               p_vntSalesOrderDetails(5, intRecordCount) = IIf(rstSelect![Level] = 1, "", rstSelect![reserved_val])
               p_vntSalesOrderDetails(6, intRecordCount) = IIf(rstSelect![vow_val] = -1, "NOT SHIPPED", rstSelect![vow_val])
               p_vntSalesOrderDetails(7, intRecordCount) = rstSelect![Status]
               p_vntSalesOrderDetails(8, intRecordCount) = IIf(rstSelect![Level] = 1, "", rstSelect![dispatch_date])

and code inside the control loads the array:

    ' Populate the sales order details fields.
    vfgSalesOrderDetails.Clear
    vfgSalesOrderDetails.Rows = 1
    blnReturn = p_objSalesOrder.GetSalesOrderDetailsArray(vntSalesOrderDetails)
    If blnReturn Then
        ' Successfully got the sales order details array.
       
        ' Set column headings based on order type.
        If p_objSalesOrder.strOrderType = "SO" Or p_objSalesOrder.strOrderType = "NW" Then
       
            ' Set up the titles for the sales order details.
            vfgSalesOrderDetails.FormatString = "Ln|Product   |Description                                                                   |Ordered|Released|Dispatched|Status                       |Dispatch Date"
        ElseIf p_objSalesOrder.strOrderType = "RO" Then
            ' Set up the titles for the return details.
            vfgSalesOrderDetails.FormatString = "Ln|Product   |Description                                       |Returned|Repair|Replace|Dispatched|Condition   |Action          |Status            |Dispatch Date"
        End If
        ' Load the grid with the array of sales order details.
        vfgSalesOrderDetails.LoadArray (vntSalesOrderDetails)          <<< this loads the grid with the array.
    Else
        ' Error occurred while getting the sales order details array.
    End If

I don't know where to put the double click function, and how i can capture the values for the order number, client, item, line number and quantity (an example on only how to cpature one would help me a lot) and pass them to the pop up form when the row is double clicked.

any help on this is greatly appreciated.

thank you..


0
Comment
Question by:itortu
  • 10
  • 9
19 Comments
 

Author Comment

by:itortu
ID: 18773965
i am using vb 6
0
 

Author Comment

by:itortu
ID: 18774252
i was thinking putting a call to a double click sub after this line:

 p_vntSalesOrderDetails(8, intRecordCount) = IIf(rstSelect![Level] = 1, "", rstSelect![dispatch_date])

Call vntSalesOrderDetails_DblClick

and inside this sub have code to pop up the form.

does this makes sense?
0
 

Author Comment

by:itortu
ID: 18775015
may be it is better to do it after the array is loaded?

vfgSalesOrderDetails.LoadArray (vntSalesOrderDetails)


the array contains 8 elements or grid columns.

could someone shoe me how to create a double click function that pops up a form. even an empty form.


0
 
LVL 5

Expert Comment

by:mah8473
ID: 18775657
I'm assuming here that you aren't wanting to specify a particular column that fires the double click event, but rather you can double click anywhere in the grid and want to open the new form to display drilled down details based on the clicked rows OrderNo

Propably the easiest way is to add a Property to your new form (OrderNo) which you can populate before loading the form with your double click on the grid

'======================
'new form code
Dim g_OrderNo as integer  'Private declaration of the form property
Public Property Get OrderNo() As Integer
    OrderNo = g_OrderNo
End Property
'Public declaration of the form property
Public Property Let OrderNo(ByVal vData As Integer)
    g_OrderNo = CInt(vData)
End Property

'in the forms load event write some code to retrive the order details based on the parsed Property for OrderNo
EG: call PopulateOrder(OrderNo) 'this routine retrieves the order and poulates the fields on the new form based on the OrderNo Property

'============
'grid double click code
Private Sub vfgSalesOrderDetails_DoubleClick()
On Error Resume Next
    With vfgSalesOrderDetails
        If .MouseRow <> 0 Then 'not the grid header row
                myNewForm.Orderno = .TextMatrix(.MouseRow,0)    'read the OrderNo from the clicked row (I'm assuming this is the forms 1st column, hence the 0)
                myNewForm.Show vbModal  'open your form modally to force the user to do something even if is just to view the Order details in more detail and then close.......by opening modally it ensures you don't have popup forms floating around in the background
        End If
    End With
End Sub

Hope this helps
Good Luck

0
 
LVL 5

Expert Comment

by:mah8473
ID: 18775777
oops when stepping through the code you may experience mixed results as .MouseRow will actually follow your mouse when you are code view..... so your probably better off using .Row....sorry about that
0
 
LVL 5

Expert Comment

by:mah8473
ID: 18775797
raaaaaa clearly I'm a little slow this morning.....In addition when you unload the new form, ensure you set the OrderNo property = 0 so it doesn't retain the value of the property in memory
EG:
OrderNo = 0
Unload me
0
 

Author Comment

by:itortu
ID: 18794127
hi again!

i have a question related to my original question.

i am filling one column of a grid with serial numbers that are part of an order.
one order can have several serial numbers.

when i load the form i place the value of the serial number like this:

Private Sub Form_Load()
    grdSerialNumber = m_strSerialNumber
End Sub

but this only places the first serial number that founds and does not loops through all.

how can i populate the column with all serial numbers

something like:

0001
0002
0003
0004
and so on...


thank you
0
 
LVL 5

Expert Comment

by:mah8473
ID: 18796819
If my suggestion was a solution to your initial problem then you should accept it as an answer and post another question as although it may be related it is actually a new question all together. That said I'll try to help you out but you might like to refer to the rules of EE for future reference.

what is "m_strSerialNumber" declared as a string? or a string array? and how/where is it being poulated?
0
 
LVL 5

Expert Comment

by:mah8473
ID: 18796930
I'm guessing it's an array

so just iterate through the array...but you'll physically need to write each serial number to the grid rows....your code "grdSerialNumber = m_strSerialNumber" would likely assume you are talking about the .Text property of grdSerialNumber

Assuming m_strSerialNumber is an array do something like
'================================
Private Sub Form_Load()

Dim m_strSerialNumber(3) As String ' I've declared this only for illustration purposes
Dim i As Integer
Dim iRowNo As Integer

m_strSerialNumber(0) = "test"  ' I've populated this only for illustration purposes
m_strSerialNumber(1) = "test1" ' I've populated this only for illustration purposes
m_strSerialNumber(2) = "test2" ' I've populated this only for illustration purposes

For i = 0 To UBound(m_strSerialNumber) - 1
    With grdSerialNumber
         iRowNo = iRowNo + 1  'retain the row count
         .Rows = .Rows + 1   ' add a new row to the grid
         .TextMatrix(iRowNo, 0) = m_strSerialNumber(i) ' fill grid iRowNo colum 0 (your serial No column) with the items from the array
   End With
Next i

End Sub

Hope this helps
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 5

Expert Comment

by:mah8473
ID: 18796942
oops didn't finish that idea in my previous comment

where I said "your code "grdSerialNumber = m_strSerialNumber" would likely assume you are talking about the .Text property of grdSerialNumber"....i forgot to mention the grid.Text Property will only refer to .text of the cell with focus....not the entre textual content of the grid.
0
 

Author Comment

by:itortu
ID: 18802552
it is working now, i just need to know how can i put a header that reads "serial number" inside this logic:

    If Not rstSelect Is Nothing Then
        If Not rstSelect.BOF And Not rstSelect.EOF Then
            Do While Not rstSelect.EOF
                r = r + 1
                grdSerialNumber.Rows = r + 1
                For c = 0 To rstSelect.RecordCount - 1
                    strSerialNumber = rstSelect![serial_number]
                    grdSerialNumber.TextMatrix(totalRecs, 0) = strSerialNumber
                Next c
                rstSelect.MoveNext
                totalRecs = totalRecs + 1
            Loop
        Else
            ' Do nothing
            'MsgBox "There are no Serial Numbers for this order. (" & Err.Number & " - " & Err.Description & ")", vbOKOnly, "Package Viewer"
        End If
    End If
0
 
LVL 5

Accepted Solution

by:
mah8473 earned 500 total points
ID: 18804626
I use a little routine I call on Form_Load to design my grids

'form level Constants for mshFlexGrid Column IDs
Const g_COL_SERIAL_NO = 0
Const g_COL_PRODUCT_CODE = 0

Private Sub DesignGrid()
On Error Resume Next
    With fgdSerialNo
        .FormatString = "<Serial No|<Product Code"   ' add column headings seperated by |
        .Rows = 1 ' this is the header row
        .Cols = 2  ' set to how many columns you want
        .ColWidth(g_COL_SERIAL_NO) = 1500 ' set to whatever width you like
        .ColWidth(g_COL_PRODUCT_CODE) = 900 ' set to whatever width you like
    End With
End Sub

and this may help you with grid poulation also....at least this is what I use....your logic above looks a little weird to me.....please don't be offended though as I'm not sure exactly sure of your usage here but your code:
For c = 0 To rstSelect.RecordCount - 1
      strSerialNumber = rstSelect![serial_number]
      grdSerialNumber.TextMatrix(totalRecs, 0) = strSerialNumber
Next c
Will be writing the same serial No to the grid rstSelect.recordcount times???
also your lines
r = r + 1
and
totalRecs = totalRecs + 1
are basically the same thing....yet used slightly differently...you really only need one line to cover both usages
Just thought I'd point it out....but again I'm not 100% on you usage so I might be on a different page to you entirely....if so please ignore me :)

You might like this code???

Private Function PopulateGrid()
    Dim adors As New ADODB.Recordset
    Dim iRowNo As Integer
On Error GoTo Err_PopulateGrid
    fgdSerialNos.Rows = 1
    If bGettSerialNos(adors) Then ' this routine retrieves and poulates my recordset....much like your rstSelect I would assume

        If Not adors.EOF Then ' (if nothing returned BOF and EOF....so no real need to test for both)
            With fgdSerialNos
                While Not adors.EOF
                    iRowNo = iRowNo + 1
                    .Rows = .Rows + 1
                    .TextMatrix(iRowNo, g_COL_PRODUCT_SERIAL_NO_ID) = adors!SerialNoID
                    .TextMatrix(iRowNo, g_COL_PRODUCT_SERIAL_NO) = adors!SerialNo
                    adors.MoveNext
                Wend
            End With
        End If
    Else
           'MsgBox "There are no Serial Numbers for this order. (" & Err.Number & " - " & Err.Description & ")", vbOKOnly, "Package Viewer"
    End If

Err_PopulateGrid:
    If Err.Number <> 0 Then
        If adors.State = adStateOpen Then
            adors.Close
        End If
        MsgBox Err.Description, , Err.Source
    End If
    Set adors = Nothing
End Function

I hope this helps.....again if I'm off on a tangent please don't be offended
0
 
LVL 5

Expert Comment

by:mah8473
ID: 18804651
oops to keep in line with my form constants

.TextMatrix(iRowNo, g_COL_PRODUCT_SERIAL_NO_ID) = adors!SerialNoID
.TextMatrix(iRowNo, g_COL_PRODUCT_SERIAL_NO) = adors!SerialNo

should've read

.TextMatrix(iRowNo, g_COL_SERIAL_NO) = adors!SerialNo
.TextMatrix(iRowNo, g_COL_PRODUCT_CODE) = adors!ProductCode

sorry about that :)
0
 

Author Comment

by:itortu
ID: 18808750
this is my form_load sub:

how can i use your routine to design my grids from my sub?

i would like to be able to control the column width and place a header the reads "Serial Number"

the grid has only one column.


Private Sub Form_Load()
   
    Dim strSql As String
    Dim strStmt As String
    Dim rstSelect As ADODB.Recordset
    Dim rsSelect As ADODB.Recordset
    Dim strSerialNumber As String
    Dim strAgressoConnection As String
    Dim totalRecs As Integer
    Dim r As Long
    Dim c As Long
    Dim i As Integer
    Dim iRowNo As Integer
     
   
    txtOrder.Text = m_strOrderNumber
    txtClient.Text = m_strClient
   
    txtQty.Text = m_strQty
   
    strSql = "    SELECT  serial_number, line_number " & _
             "    FROM    bhuserial_number " & _
             "    WHERE   order_id = '" & m_strOrderNumber & "' " & _
             "    AND     client = '" & m_strClient & "'"
   
    Set rstSelect = m_cnnAgresso.Execute(strSql)
   
    txtLineNo.Text = rstSelect![line_number]
       
    strStmt = "    SELECT  item_number " & _
             "    FROM    t_order_detail " & _
             "    WHERE   order_number = '" & m_strOrderNumber & "' " & _
             "    AND     client = '" & m_strClient & "'"
   
    Set rsSelect = m_cnnHighJump.Execute(strStmt)
   
    txtItem = rsSelect![item_number]
   
    If Not rstSelect Is Nothing Then
        If Not rstSelect.BOF And Not rstSelect.EOF Then
            Do While Not rstSelect.EOF
                r = r + 1
                grdSerialNumber.Rows = r + 1
                For i = 0 To rstSelect.RecordCount - 1
                        strSerialNumber = rstSelect![serial_number]
                        grdSerialNumber.TextMatrix(totalRecs, 0) = strSerialNumber
                Next
                rstSelect.MoveNext
                totalRecs = totalRecs + 1
            Loop
        Else
            ' Do nothing
        End If
    End If

   
End Sub
0
 

Author Comment

by:itortu
ID: 18808896
i implemented your routine, but i get only the first row (header) Serial No
and the rows with the serial numbers have disappear.

Private Sub DesignGrid()
On Error Resume Next
    With grdSerialNumber
        .FormatString = "Serial No"   ' add column headings seperated by |
        .Rows = 1 ' this is the header row
        .Cols = 1  ' set to how many columns you want
        .ColWidth(g_COL_SERIAL_NO) = 5000 ' set to whatever width you like
    End With
End Sub

    If Not rstSelect Is Nothing Then
        If Not rstSelect.BOF And Not rstSelect.EOF Then
            Do While Not rstSelect.EOF
                r = r + 1
                grdSerialNumber.Rows = r + 1
                For i = 0 To rstSelect.RecordCount - 1
                        strSerialNumber = rstSelect![serial_number]
                        grdSerialNumber.TextMatrix(totalRecs, g_COL_SERIAL_NO) = strSerialNumber
                       
                Next
                rstSelect.MoveNext
                totalRecs = totalRecs + 1
                Call DesignGrid
            Loop
        Else
            ' Do nothing
        End If
       
    End If

0
 

Author Comment

by:itortu
ID: 18809204
ok i think it works somehow now

                For i = 0 To rstSelect.RecordCount - 1
                        strSerialNumber = rstSelect![serial_number]
                        grdSerialNumber.FormatString = "Serial No"
                        grdSerialNumber.ColWidth(g_COL_SERIAL_NO) = 1335
                        grdSerialNumber.TextMatrix(totalRecs, g_COL_SERIAL_NO) = strSerialNumber
                       
                Next

how can the background of the header row be set as grey, to make it different from the rows with the serial numbers?
0
 

Author Comment

by:itortu
ID: 18809413
never mind i did it on the properties window setting a fixed row of 1

thank you.
0
 

Author Comment

by:itortu
ID: 18809486
it iw working, but i was not able to figure out te counter the way you have it.
if you could help me making the logic more congruent that'll be great.


Private m_strSerialNumber As String
 
  strSql = "    SELECT  serial_number, line_number " & _
             "    FROM    bhuserial_number " & _
             "    WHERE   order_id = '" & m_strOrderNumber & "' " & _
             "    AND     client = '" & m_strClient & "'"
   
    Set rstSelect = m_cnnAgresso.Execute(strSql)

    If Not rstSelect Is Nothing Then
        If Not rstSelect.BOF And Not rstSelect.EOF Then
            Do While Not rstSelect.EOF
                r = r + 1
                grdSerialNumber.Rows = r + 1
                For i = 0 To rstSelect.RecordCount - 1
                        strSerialNumber = rstSelect![serial_number]
                        grdSerialNumber.FormatString = "Serial No"
                        grdSerialNumber.ColWidth(g_COL_SERIAL_NO) = 1335
                        grdSerialNumber.TextMatrix(totalRecs, g_COL_SERIAL_NO) = strSerialNumber
                       
                Next
                rstSelect.MoveNext
                totalRecs = totalRecs + 1
            Loop
        Else
            ' Do nothing
        End If


0
 
LVL 5

Expert Comment

by:mah8473
ID: 18812848
to use my DesignGrid routine simply add this "Call DesignGrid()"  to your Form_Load....I usually do this before anything else

I just tested you code and my grid fills every line with the same serial No??? Which is what I suggested it would probably do earlier in my comments.

Here's a very simple example of the whole form (using your select statement) which is (kind of) how I would write it and in this example I'm assuming your rstSelect is populated with multiple serial no's, of which you want to display all of them in the grid...

Everyone has their own style of coding so I'm not suggesting this is a better way to do it....but the logic of your grid population certainly looks a little screwy
'----------------------------------
Option Explicit

Dim m_strOrderNumber As Integer
Dim m_strClient As String
'form level Constants for mshFlexGrid Column IDs
Const g_COL_SERIAL_NO = 0
'-----------------------------------------
Private Sub DesignGrid()
On Error Resume Next
    With fgdSerialNos
        .FormatString = "<Serial No"   ' add column headings seperated by |
        .Rows = 1 ' this is the header row
        .Cols = 1  ' set to how many columns you want
        .ColWidth(g_COL_SERIAL_NO) = 1500 ' set to whatever width you like
    End With
End Sub
'-----------------------------------------
Private Sub Form_Load()
On Error Resume Next
    'I can't see in your code how you've populated these so I'm just adding something random here
    m_strOrderNumber = 1
    m_strClient = "someClient"

   Call DesignGrid 'set up the design of the Grid
   Call PopulateGrid 'populated the Grid
End Sub
'-----------------------------------------
Private Function PopulateGrid()
    Dim adors As New ADODB.Recordset
    Dim iRowNo As Integer
    Dim strSQL As String
       
On Error GoTo Err_PopulateGrid
    fgdSerialNos.Rows = 1 'ONLY display the header Row at this point ie; ROW zero
   
    strSQL = "    SELECT  serial_number, line_number " & _
             "    FROM    bhuserial_number " & _
             "    WHERE   order_id = '" & m_strOrderNumber & "' " & _
             "    AND     client = '" & m_strClient & "'"
   
    Set adors = m_cnnAgresso.Execute(strSQL)

    If Not adors.EOF Then
        With fgdSerialNos
            While Not adors.EOF ' loop through the recordset and add SerialNo's to the grid
                iRowNo = iRowNo + 1 ' add 1 to the row counter
                .Rows = .Rows + 1 'add a row to the grid
                .TextMatrix(iRowNo, g_COL_SERIAL_NO) = adors!SerialNo 'fill the grid
                adors.MoveNext 'move to the next record
            Wend
        End With
    End If

Err_PopulateGrid:
    If Err.Number <> 0 Then
        If adors.State = adStateOpen Then
            adors.Close
        End If
        MsgBox Err.Description, , Err.Source
    End If
    Set adors = Nothing
End Function
'-----------------------------------------

I hope this helps, good luck
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
This article will show, step by step, how to integrate R code into a R Sweave document
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now