Solved Edit and update some field via vba error

1654449733049.png

1654449749182.png

Yes, code like that.

Still didn't answer my questions.
Why save institution code and other institution info - why not just save the institution code?
other are info are not connector
so need to insert other info
 
@Akai90

"sorry i am new in access
and my english is not good enough"

Write a description of what you are trying to do and what you expect as result in your native language.
Use google Translate to make an English translation
Copy and post the English version
 
C#:
  Dim db As Database
  Dim rec As Recordset
      Set db = CurrentDb
      Set rec = db.OpenRecordset("Select * from TGuruIPS")
      rec.Edit
          rec("KodInstitusi") = Me.textkodips
          rec("JenisInstitusi") = Me.textjenisips
          rec("Institusi") = Me.textnamaips
          rec("Alamat") = Me.textalamatpenuh
          rec.Update
      rec.Close
   DoCmd.OpenQuery "qListGuru"
  Me![listsemuaguru].Requery
    DoCmd.Close
    DoCmd.OpenQuery "QListFilterGuru"
Me![listgurufilterips].Requery
DoCmd.Close

my latest vba code..
got no error but fields not edit and update
 
Your latest code does not have filter criteria in the SQL statement. Are you sure a record is not edited? Just first record of recordset is edited and without filter criteria, most likely not the one you want.
 
I am going to say this just one more time. :(
Walk through your code line by line, and inspect variables/fields.
 
You cannot not move records if no records exist?
Test for EOF before attempting anything on any records.
Why are you even moving last then first.?

You need to understand what each line of code does. You can't just write code without knowing what it actually does :(

I know at least one other person who does, and they have the same problems, time and time again.
You need to understand the code you write.
That is the only way you are going to progress, believe me.
 
.MoveLast
.MoveFirst

was my suggested code. Building from memory. Gasman is correct, should not be needed. Since you removed them in lastest code, should no longer be issue. But again, the SQL does not have filter criteria.
 
.MoveLast
.MoveFirst

was my suggested code. Building from memory. Gasman is correct, should not be needed. Since you removed them in lastest code, should no longer be issue. But again, the SQL does not have filter criteria.
O/P was doing it from first post. :(
Then checking for EOF. :(
 
No, code in post #1 was using Seek. I introduced MoveLast MoveFirst in post #5. Definitely my goof.
 
try to modify your code to check for .EOF and .NoMatch:
Code:
Private Sub listsemuaguru_DblClick(Cancel As Integer)
Me![listgurufilterips].Requery
Dim tguru As Integer, RESPON As String
Dim MyDB As DAO.Database, MyTable As DAO.Recordset
Dim JWBCONFIRM As String

    Set MyDB = CurrentDb
    Set MyTable = MyDB.OpenRecordset("TGuruIPS", DB_OPEN_TABLE)
    With MyTable
        'check if there is record in the table
        If Not (.BOF And .EOF) Then
            MyTable.Index = "NamaGuru"
            MyTable.Seek "=", Forms![FkemaskiniPG]![listsemuaguru]
            'check if we found the record
            If Not .NoMatch Then
                .Edit
                !KodInstitusi = [kodips]
                !JenisInstitusi = [jenisips]
                !Institusi = [namaips]
                !Alamat = [alamatpenuh]
                .Update
            End If
        End If
        .Close
    End With
    DoCmd.OpenQuery "qListGuru"
    Me![listsemuaguru].Requery
    DoCmd.Close
    DoCmd.OpenQuery "QListFilterGuru"
    Me![listgurufilterips].Requery
    DoCmd.Close
End Sub
 
Again, open filtered recordset and Seek is not needed.
 
C#:
Private Sub listsemuaguru_DblClick(Cancel As Integer)
Dim clnpusatini As Integer, RESPON As String
  Dim db As Database
  Dim rec As Recordset
      Set db = CurrentDb
      Set rec = db.OpenRecordset("SELECT * FROM TGuruIPS WHERE NamaGuru='" & Forms![FkemaskiniPG]![listsemuaguru] & "'")


      rec.Edit
          rec("KodInstitusi") = Me.textkodips
          rec("JenisInstitusi") = Me.textjenisips
          rec("Institusi") = Me.textnamaips
          rec("Alamat") = Me.textalamatpenuh
          rec.Update
      rec.Close
   DoCmd.OpenQuery "qListGuru"
  Me![listsemuaguru].Requery
    DoCmd.Close
    DoCmd.OpenQuery "QListFilterGuru"
Me![listgurufilterips].Requery
DoCmd.Close
End Sub

old code are not problem..
my problem is query builder
NamaGuru i put second row..
when i put first row all error gone..

thanks for the help
 

Users who are viewing this thread

Back
Top Bottom