Results 1 to 9 of 9

Thread: Please correct my codes...

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    185

    Please correct my codes...

    Dear Experts,

    Has anyone could help me please for these code?

    visual basic code:
    Private Sub cmdCheckCurrentRecord_Click()

    Dim con As ADODB.Connection
    Set con = New ADODB.Connection
    con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\exercise.mdb"
    Set rst = Execute_SQL_ReturnRecordSet("Select * from Item", False, "C:\exercise.mdb")

    rst.MoveFirst
    Do While rst.EOF = False
    If UserForm1.txtqty.Text = rst.Fields("Item_Code").Value Then
    Exit Do
    End If
    rst.MoveNext
    Loop

    TextBox3.Text = rst.Fields("Qty")

    Application.ScreenRefresh
    End Sub






    When I select item no 1, then when I press "Check Current Stock" it show its Qty...BUT, when I select other item numbers, let say item code number 3 it still show the Qty for item number 1...???....

    Please help with code corrections...

    Thank you so much...

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Please correct my codes...

    From what are you selecting the item? A combo box? Listbox? What?

    It would appear you would need to add a WHERE clause in your SELECT statement to uniquely identify the specific item and gets its quantity, but I don't know how you are making your selection as it is.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    185

    Re: Please correct my codes...

    Hi,

    Thanks for your reply...it is from a combobox...would you please correct my code please....????..I tried many time and finally get frustrated....

    OR do you want to see all codes (I mean the file, so you can have a look trough it..???)..

    Thank you so much...

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Please correct my codes...

    My SELECT would be something like
    VB Code:
    1. "Select * from Item WHERE fieldname = '" & Combo1.List(Combo1.ListIndex) & "' "
    Where fieldname is the name of your database field that stores the item and Combo1 is the name of your combo box.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    185

    Re: Please correct my codes...

    Hi,

    I did what you directed but received error message:

    I did like this:

    VB Code:
    1. Private Sub cmd_CheckCurrent_Click()
    2.  
    3. Dim con As ADODB.Connection
    4.     Set con = New ADODB.Connection
    5.     con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\exercise.mdb"
    6.         Set rst = Execute_SQL_ReturnRecordSet("Select * from Item WHERE fieldname = '" & cmb_item.List(cmb_item.ListIndex) & "' ", False, "C:\exercise.mdb")
    7.    
    8.          rst.MoveFirst
    9. Do While rst.EOF = False
    10.     If UserForm1.txtqty.Text = rst.Fields("Item_Code").Value Then
    11.        Exit Do
    12.     End If
    13.     rst.MoveNext
    14. Loop
    15.  
    16.    
    17.        
    18.     Application.ScreenRefresh
    19.  
    20. End Sub

    I did following error: Run Time Error '381': Could not get the list property. Invalid property array index.

    If you dont mind...would you please have a look into my file to see what happens please..???....It is on the "Check Current Stock"...

    Thank you so much for your kind helps....
    Attached Files Attached Files

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Please correct my codes...

    Is the name of the field in your database fieldname?

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    185

    Re: Please correct my codes...

    Hi,

    I already changed it to my fieldname 's name...but still get the same error which is Run Time Error 381....

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    185

    Re: Please correct my codes...

    Hi,

    Sorry...when I changed the fieldname with Item_Code...there is a new error message:

    Run Time Error 3021: Either BOF or EOF is True, or the current record has been deleted. Requested operations requires a current record. And "rst.MoveFirst" was yellow highlight....

  9. #9
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Please correct my codes...

    Have you made a selection in your combobox?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

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