Results 1 to 22 of 22

Thread: Statement to get data from txtSearchID and ...

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    287

    Statement to get data from txtSearchID and ...

    Hi,

    I have one MSHFlexGrid that should show data from MS Access database. I have one textbox "txtSearchID". When I click on cmdDetails, it should get the number from txtSearchID and show the related records in MSHFlexGrid.

    The following code works fine:

    VB Code:
    1. rs.Open "Select Sid, Scustname, Sdate, Sitemno, Sqty from Supplied ", db
    2. Set MSHFlexGrid1.DataSource = rs

    But the following code to get data from txtSearchID and show records is not working...simply it shows nothing.

    The following is the code (Which is not showing any record except the column headers:

    VB Code:
    1. rs.Open "Select Sid, Scustname, Sdate, Sitemno, Sqty from Supplied Where Sid='txtSearchID'", db
    2. Set MSHFlexGrid1.DataSource = rs

    Regards,

    Margaret

  2. #2

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    287

    Re: Statement to get data from txtSearchID and ...

    Quote Originally Posted by BillGeek
    Try replacing it with:
    VB Code:
    1. rs.Open "Select Sid, Scustname, Sdate, Sitemno, Sqty from Supplied Where Sid='" & txtSearchID.Text & "'", db
    Getting the following error:

    Operation is not allowed when the object is open.

    But the following code doesn't give any error:

    VB Code:
    1. rs.Open "Select Sid, Scustname, Sdate, Sitemno, Sqty from Supplied", db

    What could be the problem?

  4. #4
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Statement to get data from txtSearchID and ...

    When you pass values thru variables always concatenate the values using &
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  5. #5
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Statement to get data from txtSearchID and ...

    Seems the rs is opened and not closed. Close the rs if it is opened before you execute this query
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    287

    Re: Statement to get data from txtSearchID and ...

    Quote Originally Posted by ganeshmoorthy
    When you pass values thru variables always concatenate the values using &
    Hi,

    Could you plz help me out.

    Margaret

  7. #7
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Statement to get data from txtSearchID and ...

    here is the code...
    VB Code:
    1. If Rs.State = adStateOpen Then
    2.     Rs.Close
    3. End If
    4. Rs.Open "Select Sid, Scustname, Sdate, Sitemno, Sqty from Supplied Where Sid='" & txtSearchID.Text & "'", db, adOpenDynamic, adLockOptimistic
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  8. #8
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Statement to get data from txtSearchID and ...

    try this with
    VB Code:
    1. rs.Open "Select Sid, Scustname, Sdate, Sitemno, Sqty from Supplied", db, adOpenDynamic, adLockOptimistic
    2. MsgBox Rs.RecordCount
    see what does it display in the msgbox
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    287

    Re: Statement to get data from txtSearchID and ...

    Quote Originally Posted by ganeshmoorthy
    here is the code...
    VB Code:
    1. If Rs.State = adStateOpen Then
    2.     Rs.Close
    3. End If
    4. Rs.Open "Select Sid, Scustname, Sdate, Sitemno, Sqty from Supplied Where Sid='" & txtSearchID.Text & "'", db, adOpenDynamic, adLockOptimistic
    The same error comes again.

    Margaret

  10. #10
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Statement to get data from txtSearchID and ...

    is it displaying...Operation is not allowed when the object is open...can you post your full code of the sub...
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    287

    Re: Statement to get data from txtSearchID and ...

    Quote Originally Posted by ganeshmoorthy
    try this with
    VB Code:
    1. rs.Open "Select Sid, Scustname, Sdate, Sitemno, Sqty from Supplied", db, adOpenDynamic, adLockOptimistic
    2. MsgBox Rs.RecordCount
    see what does it display in the msgbox
    Msgbox shows "3" (and I have 3 records in table Supplied).

    Margaret

  12. #12
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Statement to get data from txtSearchID and ...

    Margaret: First try to solve one by one. what is the actual problem now...
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    287

    Re: Statement to get data from txtSearchID and ...

    Quote Originally Posted by ganeshmoorthy
    Margaret: First try to solve one by one. what is the actual problem now...
    Ok.

    VB Code:
    1. Private Sub Form_Load()
    2.     Call SetGrid
    3. End Sub

    VB Code:
    1. Public Sub SetGrid()
    2.  
    3.     If rs.State = adStateOpen Then
    4.         rs.Close
    5.     End If
    6.    
    7. Rs.Open "Select Sid, Scustname, Sdate, Sitemno, Sqty from Supplied Where Sid='" & txtSearchID.Text & "'", db, adOpenDynamic, adLockOptimistic
    8. 'MsgBox rs.RecordCount
    9.  
    10. Set MSHFlexGrid1.DataSource = rs
    11. Call MSHFlexDatagrid_Columns
    12.  
    13. MSHFlexGrid1.SelectionMode = flexSelectionByRow
    14. MSHFlexGrid1.FocusRect = flexFocusNone
    15.  
    16. End Sub

    VB Code:
    1. Private Sub MSHFlexDatagrid_Columns()
    2.  
    3.     MSHFlexGrid1.ColWidth(0) = 700
    4.     MSHFlexGrid1.ColWidth(1) = 5500
    5.     MSHFlexGrid1.ColWidth(2) = 1300
    6.     MSHFlexGrid1.ColWidth(3) = 1300
    7.     MSHFlexGrid1.ColWidth(4) = 1100
    8.        
    9.     MSHFlexGrid1.TextMatrix(0, 0) = " ID"
    10.     MSHFlexGrid1.TextMatrix(0, 1) = "Customer Name"
    11.     MSHFlexGrid1.TextMatrix(0, 2) = "Date"
    12.     MSHFlexGrid1.TextMatrix(0, 3) = "Item No."
    13.     MSHFlexGrid1.TextMatrix(0, 4) = "S. Qty."
    14.    
    15.     MSHFlexGrid1.ColAlignment(0) = 4
    16.     MSHFlexGrid1.ColAlignment(1) = 2
    17.     MSHFlexGrid1.ColAlignment(2) = 4
    18.     MSHFlexGrid1.ColAlignment(3) = 4
    19.     MSHFlexGrid1.ColAlignment(4) = 6
    20.    
    21.     MSHFlexGrid1.ColAlignmentFixed(0) = 4
    22.     MSHFlexGrid1.ColAlignmentFixed(1) = 2
    23.     MSHFlexGrid1.ColAlignmentFixed(2) = 4
    24.     MSHFlexGrid1.ColAlignmentFixed(3) = 4
    25.     MSHFlexGrid1.ColAlignmentFixed(4) = 6
    26.  
    27. Dim X As Long
    28.     With MSHFlexGrid1
    29.    
    30.     For X = .FixedRows To .Rows - 1
    31.         .TextMatrix(X, 4) = Format(.TextMatrix(X, 4), "#,0")
    32.         Next X
    33.         End With
    34.  
    35. End Sub

    Getting error: 3705
    Operation is not allowed when the object is open.

    This is the error what I am getting right now.

    Margaret

  14. #14
    VB Guru ganeshmoorthy's Avatar
    Join Date
    Dec 2005
    Location
    Sharjah, United Arab Emirates
    Posts
    3,031

    Re: Statement to get data from txtSearchID and ...

    which line is getting highlighted, when this error occurs...
    If an answer to your question has been helpful, then please, Rate it!

    Have done Projects in Access and Member management systems using BioMetric devices, Smart cards and BarCodes.


  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    287

    Re: Statement to get data from txtSearchID and ...

    Quote Originally Posted by ganeshmoorthy
    which line is getting highlighted, when this error occurs...
    Hi,

    I am attaching my project here. Please have a look at it and help me out. I need to get the total supplied quantity in txtSqty.

    Regards,

    Margaret
    Attached Images Attached Images  
    Attached Files Attached Files

  16. #16
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Jar, Norway
    Posts
    372

    Re: Statement to get data from txtSearchID and ...

    To me it look like you are missing
    VB Code:
    1. Set rs = New ADODB.Recordset
    above:
    Rs.Open "Select Sid, Scustname, Sdate, Sitemno ....................
    Last edited by Ember; Dec 13th, 2006 at 07:32 AM.

  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    287

    Re: Statement to get data from txtSearchID and ...

    Quote Originally Posted by Ember
    To me it look like you are missing
    VB Code:
    1. Set rs = New (ADODB.)Recordset
    above:
    Rs.Open "Select Sid, Scustname, Sdate, Sitemno ....................
    Still the same error occurs. You can have a look at my project which was attahced with name "Purchase Orders.zip". In this project frmSDetails giving the error.

    Margaret

  18. #18
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Jar, Norway
    Posts
    372

    Re: Statement to get data from txtSearchID and ...

    This works:
    VB Code:
    1. Public Sub SetGrid()
    2.  
    3. '    If rs.State = adStateOpen Then
    4. '        rs.Close
    5. '    End If
    6. Set rs = New ADODB.Recordset
    7. rs.Open "Select Sid, Scustname, Sdate, Sitemno, Sqty from Supplied", db, adOpenDynamic, adLockOptimistic
    8.  
    9. Set MSHFlexGrid1.DataSource = rs
    10. Call MSHFlexDatagrid_Columns
    11.  
    12. MSHFlexGrid1.SelectionMode = flexSelectionByRow
    13. MSHFlexGrid1.FocusRect = flexFocusNone
    14.  
    15. End Sub

    Morten

  19. #19
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Jar, Norway
    Posts
    372

    Re: Statement to get data from txtSearchID and ...

    Here you call Call SetGrid twice:
    VB Code:
    1. frmSDetails.SetGrid
    2. frmSDetails.Show
    3. frmSDetails.Top = 4360
    4. frmSDetails.Left = 660
    5. frmSDetails.txtSearchID = txtID
    First by frmSDetails.SetGrid
    Then by frmSDetails.Show ( in Form_Load: Call SetGrid)

    And
    VB Code:
    1. frmSDetails.Left = 660
    2. frmSDetails.Top = 4360
    3. 'frmSDetails.txtSearchID = frmLPO.txtID ' If txtId is Public or TextBox.Name in frmLPO
    is best inside Form_LOad of frmSDetails

    Nice program!
    Morten
    Last edited by Ember; Dec 13th, 2006 at 09:10 AM.

  20. #20

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    287

    Re: Statement to get data from txtSearchID and ...

    Quote Originally Posted by Ember
    Here you call Call SetGrid twice: Name in frmLPO.
    Morten
    Hi, thanks for your reply. How to modify it now. Please explain a little bit with an example.

    Margaret.

  21. #21
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Jar, Norway
    Posts
    372

    Re: Statement to get data from txtSearchID and ...

    I'm at work now, but will look through the project later. At the first glance I find it hard to follow what actually the recordset 'rs' is filled up with or contains after been through different Sub routines. Maybe it's an idea to have one recordset to refill and empty, and one to keep original records. Or just have one to search and move through?
    I'll come back later! Morten

  22. #22
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Jar, Norway
    Posts
    372

    Re: Statement to get data from txtSearchID and ...

    Puh! Best Margaret, you have made a nice looking application, but with the timer in the UserControl to refresh the commandButtons, it is hard to debug. Managed to edit and update a new record nevertheless. Errors here (changes made bold):
    VB Code:
    1. BS = BS + txtSqty - [B]Val([/B]txtOqty[B])[/B]
    2. [B]If Len(txtPodate) Then [/B] .Fields("Podate").Value = CDate(txtPodate.Text) [B]Else .Fields("Podate").Value = Now()[/B]
    3. .Fields("Qty").Value = [B]Val([/B]txtQty.Text[B])[/B]
    4. .Fields("Price").Value = CCur([B]IIf(txtPrice.Text <> "", [/B] txtPrice.Text[B], 0))[/B]
    5. .Fields("Amount").Value = CCur([B]IIf(txtAmount.Text <> "", [/B] txtAmount.Text[B], 0))[/B]
    But with so many different Call subroutine with even new Call subroutines inside them, you end up with a project that looks nice, but hard to make stable. Try with Breakpoints in every routine in the forms and see how often they are hit.
    To rebuild the program for an outsider like me, is almost impossible.
    Perhaps I take courage and try again?
    Last edited by Ember; Dec 14th, 2006 at 02:27 PM.

Posting Permissions

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



Click Here to Expand Forum to Full Width