VB6 cannot show data some parts of form (Access 2007)-VBForums
Results 1 to 8 of 8

Thread: VB6 cannot show data some parts of form (Access 2007)

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2017
    Posts
    4

    VB6 cannot show data some parts of form (Access 2007)

    I uses VB6 and connects database Access2007 on Windows10
    Some parts can show successfully but some cannot.
    From the below picture, when I press 1, the program does not show data.
    Could you please help me sort this out?

    Thank you in advance.

    Name:  1492103194663.jpg
Views: 147
Size:  33.3 KB

    My code is:


    Code:
    Private Sub Command1_Click()
    Dim sqlSup As String
    Dim rsSup As New ADODB.Recordset
    Dim i, j As Integer
    GridSUP.Visible = True
    sqlSup = "SELECT daydo,sym,goodidss,unitprice FROM rec_saledetail"
    sqlSup = sqlSup & " where cowid='" & txt_cow.Caption & "'"
    sqlSup = sqlSup & " ORDER BY daydo DESC"
    With rsSup
        If .State = adStateOpen Then .Close
        .ActiveConnection = conn
        .CursorType = adOpenDynamic
        .CursorLocation = adUseClient
        .Open sqlSup
    End With
                With GridSUP
                    .Rows = 2: .Cols = 4
                    For i = 0 To .Cols - 1
                            .FixedAlignment(i) = flexAlignCenterCenter
                    Next
                    .ColWidth(0) = 1000
                    .ColWidth(1) = 6000
                    .ColWidth(2) = 2000
                    .ColWidth(3) = 1200
                    .TextMatrix(0, 0) = "วันที่": .ColAlignment(0) = flexAlignCenterCenter: .ColWidth(0) = 1200
                    .TextMatrix(0, 1) = "รายละเอียด": .ColAlignment(1) = flexAlignCenterCenter: .ColWidth(1) = 5800
                    .TextMatrix(0, 2) = "ชื่อยา": .ColAlignment(2) = flexAlignCenterCenter: .ColWidth(2) = 1500
                    .TextMatrix(0, 3) = "จำนวน": .ColAlignment(3) = flexAlignCenterCenter: .ColWidth(3) = 1000
                    For j = 1 To rsSup.RecordCount
                            .TextMatrix(j, 0) = rsSup.Fields(0).Value
                            .TextMatrix(j, 1) = rsSup.Fields(1).Value
                            .TextMatrix(j, 2) = rsSup.Fields(2).Value
                            .TextMatrix(j, 3) = rsSup.Fields(3).Value
                            rsSup.MoveNext
                            .Rows = .Rows + 1
                    Next
                End With
                GridSUP.Refresh
                GridSUP.SetFocus
    
    End Sub

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    11,847

    Re: VB6 cannot show data some parts of form (Access 2007)

    Have you checked to see that records are being returned fro the db?

    what is txt_cow.Caption ?

    txt implies text box but caption implies label.

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2017
    Posts
    4

    Re: VB6 cannot show data some parts of form (Access 2007)

    Quote Originally Posted by DataMiser View Post
    Have you checked to see that records are being returned fro the db?

    what is txt_cow.Caption ?

    txt implies text box but caption implies label.

    This is the label name for storing data from the screen. It will store An025 to query data and then will show on the table.

  4. #4
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    11,847

    Re: VB6 cannot show data some parts of form (Access 2007)

    So should I take it that you have not checked to see if the query is returning records or not?
    Have you tried stepping through the code yet to see what it is doing? If not then that should be your first step.

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2017
    Posts
    4

    Re: VB6 cannot show data some parts of form (Access 2007)

    Quote Originally Posted by DataMiser View Post
    So should I take it that you have not checked to see if the query is returning records or not?
    Have you tried stepping through the code yet to see what it is doing? If not then that should be your first step.
    Thank you for your suggestion. Could you please tell me how to check the return records? Is it Debug Menu?

    Thank you in advance.

  6. #6
    PowerPoster SamOscarBrown's Avatar
    Join Date
    Aug 2012
    Location
    NC, USA
    Posts
    6,003

    Re: VB6 cannot show data some parts of form (Access 2007)

    Right after .Open sqlSup, insert this line...(before End With)

    Code:
    Debug.Print .RecordCount
    If you look at the intermediate window after you run it, if your query returns any records, it will be greater than zero.

  7. #7

    Thread Starter
    New Member
    Join Date
    Apr 2017
    Posts
    4

    Re: VB6 cannot show data some parts of form (Access 2007)

    Quote Originally Posted by SamOscarBrown View Post
    Right after .Open sqlSup, insert this line...(before End With)

    Code:
    Debug.Print .RecordCount
    If you look at the intermediate window after you run it, if your query returns any records, it will be greater than zero.
    Thank you very much. I will try it and let you know.

  8. #8
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    11,847

    Re: VB6 cannot show data some parts of form (Access 2007)

    Breakpoints and stepping through code are tools that all coders should be aware of and use when trying to solve issues, especially beginners as it can give them a better understanding of code flow.

    To set a breakpoint either click if the gray area to the left of the line of code you want to stop at or select that line and press F9
    Note that not all lines can be set as a break point, Dim statements for example can not be a breakpoint.

    When you execute the code it will pause when it gets to the breakpoint and highlight that line in the IDE, from there you can hover your mouse over vars to see what the value is, you can hit F8 to execute that line and step to the next line. Hitting F8 repeatedly will step line to line to line and allow you to see which lines are executing which can of cours ebe useful both for learning and understanding code flow and for seeing when the code fails to enter an If statement you think it should, or sticking in a loop or any number of other things.

    Breakpoints, Step mode and Debug.Print are some of the best tools for understanding what your code is doing and locating potential issues within.

    IMO this is one of the first things any would be programmer should learn.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.