Solved Edit and update some field via vba error (1 Viewer)

Akai90

Member
Local time
Tomorrow, 02:19
Joined
Feb 8, 2022
Messages
65
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
 

jdraw

Super Moderator
Staff member
Local time
Today, 14:19
Joined
Jan 23, 2006
Messages
15,364
@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
 

Akai90

Member
Local time
Tomorrow, 02:19
Joined
Feb 8, 2022
Messages
65
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
 

June7

AWF VIP
Local time
Today, 10:19
Joined
Mar 9, 2014
Messages
5,423
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.
 

Gasman

Enthusiastic Amateur
Local time
Today, 18:19
Joined
Sep 21, 2011
Messages
14,046
I am going to say this just one more time. :(
Walk through your code line by line, and inspect variables/fields.
 

Gasman

Enthusiastic Amateur
Local time
Today, 18:19
Joined
Sep 21, 2011
Messages
14,046
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.
 

June7

AWF VIP
Local time
Today, 10:19
Joined
Mar 9, 2014
Messages
5,423
.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.
 

Gasman

Enthusiastic Amateur
Local time
Today, 18:19
Joined
Sep 21, 2011
Messages
14,046
.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. :(
 

June7

AWF VIP
Local time
Today, 10:19
Joined
Mar 9, 2014
Messages
5,423
No, code in post #1 was using Seek. I introduced MoveLast MoveFirst in post #5. Definitely my goof.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 02:19
Joined
May 7, 2009
Messages
19,169
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
 

June7

AWF VIP
Local time
Today, 10:19
Joined
Mar 9, 2014
Messages
5,423
Again, open filtered recordset and Seek is not needed.
 

Akai90

Member
Local time
Tomorrow, 02:19
Joined
Feb 8, 2022
Messages
65
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

Top Bottom