Results 1 to 6 of 6

Thread: [RESOLVED] a question of query

  1. #1

    Thread Starter
    Fanatic Member ksuwanto8ksd's Avatar
    Join Date
    Apr 2005
    Posts
    636

    Resolved [RESOLVED] a question of query

    I have a tabel from access 2k with field:

    NoNota (autonumber)
    tanggal (date)
    kodepelanggan (text)
    namapelanggan (text)
    subtotal (number)
    pot (number)
    total (number)

    when I query msql = "insert...." it work fine and autonumber created,
    at the same the msql = "select * from..." doesnot return an autonumber
    on form textbox.
    I use command call save1 in the button click event

    run time error
    "either BOF or EOF is true, or the current record has been deleted."
    "requested operation require a current record"


    any sugestion is very much appreciated
    thanks in advance
    VB Code:
    1. Sub Save1()
    2. Dim msql As String
    3.  
    4. msql = "insert into tbnotajual(tanggal)values('" & dptanggal & "')"
    5.  
    6. con_data.Execute (msql)
    7. rs.Requery
    8.  
    9. msql = "select * from tbnotajual" & _
    10.        "where nonota in (select max(NoNota) from tbnotajual)"
    11.  
    12. txtnota.Text = rs.Fields(Val("NoNota"))
    13. con_data.Execute (msql)
    14. rs.Requery
    15. txtkodebarang.SetFocus
    16.  
    17. End Sub

  2. #2
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: a question of query

    try this
    VB Code:
    1. txtnota.Text = rs.Fields(Val("NoNota"))
    VB Code:
    1. if rs.eof=true then
    2. rs.movefirst
    3. end if
    4. txtnota.Text = rs.Fields(Val("NoNota"))

  3. #3
    Addicted Member Cristian's Avatar
    Join Date
    Jun 2006
    Posts
    228

    Re: a question of query

    I think that your problem is with the requery method.
    try declaring another recordset

    Dim rs1 as recordset

    Set rs1=con_data.Execute(msql)
    Set rs=rs1

  4. #4

    Thread Starter
    Fanatic Member ksuwanto8ksd's Avatar
    Join Date
    Apr 2005
    Posts
    636

    Re: a question of query

    Quote Originally Posted by danasegarane
    try this
    VB Code:
    1. txtnota.Text = rs.Fields(Val("NoNota"))
    VB Code:
    1. if rs.eof=true then
    2. rs.movefirst
    3. end if
    4. txtnota.Text = rs.Fields(Val("NoNota"))
    thanks for replays

    now the error line is:

    rs.movfirst

    VB Code:
    1. if rs.eof=true then
    2. rs.movefirst
    3. end if
    4. txtnota.Text = rs.Fields(Val("NoNota"))

  5. #5
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: a question of query

    VB Code:
    1. Sub Save1()
    2. Dim msql As String
    3. Dim rsTmp As ADODB.Recordset
    4.  
    5. msql = "insert into tbnotajual(tanggal)values('" & dptanggal & "')"
    6. con_data.Execute msql
    7.  
    8. msql = "select * from tbnotajual" & _
    9.        "where nonota in (select max(NoNota) from tbnotajual)"
    10. Set rsTmp = con_data.Execute(msql)
    11. If Not (rsTmp Is Nothing) Then
    12.    If (Not rsTmp.BOF) And (Not rsTmp.EOF) Then
    13.       txtnota.Text = rsTmp.Fields("NoNota").Value
    14.    End If
    15.    rsTmp.Close  
    16. End If
    17. 'rs.Requery  'why are you requerying this recordset? what is its query?
    18. txtkodebarang.SetFocus
    19.  
    20. End Sub

  6. #6

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