Edit specific row in table (1 Viewer)

FreonIceMan

Registered User.
Local time
Today, 13:26
Joined
May 31, 2011
Messages
19
I have a report that I run which has PT_Ins_ID in it, I am trying to edit that row with the following code. I have been searching how to do this and I haven't had any luck. If I am doing something wrong or if someone know of a way to do this with vba it would be appreciated.
Thanks,

Freon
:banghead:

PT_Ins_ID is the primary key of dbo_Patient_Insurance

Code:
Private Sub cmd_Deact_Click()
    Dim rs As DAO.Recordset
    Set rs = CurrentDb.OpenRecordset("dbo_Patient_Insurance")
    If rs.RecordCount <> 0 Then
        With rs
            .FindFirst "PT_Ins_ID" = Me.txt_PT_Ins_ID
            If Not .NoMatch Then
                .Edit
                    .Fields("PT_Ins_Active").Value = 0
                    .Fields("PT_Ins_Inactive_Date") = Now()
                    .Fields("PT_Ins_Deactivating_User") = (Environ$("Username"))
                .Update
            End If
        End With
    End If


End Sub

I've also tried this.
Code:
Dim rs_PI As DAO.Recordset
Set rs_PI = CurrentDb.OpenRecordset("dbo_Patient_Insurance")

DoWhile ("PT_Ins_ID") <> Me.txt_PT_Ins_ID
    rs_PI.MoveNext
Loop

rs_PI.Edit
rs_PI("PT_Ins_Active").Value = 0
rs_PI("PT_Ins_Inactive_Date") = Now()
rs_PI("PT_Ins_Deactivating_User") = (Environ$("Username"))
rs_PI.Update
 

CJ_London

Super Moderator
Staff member
Local time
Today, 18:26
Joined
Feb 19, 2013
Messages
16,705
try

Code:
.FindFirst "PT_Ins_ID = " & Me.txt_PT_Ins_ID
 

FreonIceMan

Registered User.
Local time
Today, 13:26
Joined
May 31, 2011
Messages
19
Hi CJ_London,

I tried your suggestion I am getting a "Compile error: Invalid or unqualified reference" the txt_PT_Ins_ID is highlighted.

your code as I have implimented it:
Code:
Private Sub cmd_Deactivate_Click()

Dim rs_PI As DAO.Recordset
Set rs_PI = CurrentDb.OpenRecordset("dbo_Patient_Insurance")

.FindFirst "PT_Ins_ID = " & Me.txt_PT_Ins_ID

rs_PI.Edit
rs_PI("PT_Ins_Active").Value = 0
rs_PI("PT_Ins_Inactive_Date") = Now()
rs_PI("PT_Ins_Deactivating_User") = (Environ$("Username"))
rs_PI.Update

End Sub
What are your thoughts?

Thanks,

Freon
 

jdraw

Super Moderator
Staff member
Local time
Today, 13:26
Joined
Jan 23, 2006
Messages
15,406
Did you try

rs_PI.FindFirst "PT_Ins_ID = " & Me.txt_PT_Ins_ID
 

FreonIceMan

Registered User.
Local time
Today, 13:26
Joined
May 31, 2011
Messages
19
I tried it and i recieved "Run-time error '3251': Operation is not supported for this type of object"

I searched for that error and found out that I needed to add ", dbOpenDynaset" to the code.

Code:
Private Sub cmd_Deactivate_Click()

Dim rs_PI As DAO.Recordset
Set rs_PI = CurrentDb.OpenRecordset("dbo_Patient_Insurance"[B][COLOR=Red], dbOpenDynaset[/COLOR][/B])

rs_PI.FindFirst "PT_Ins_ID = " & Me.txt_PT_Ins_ID

rs_PI.Edit
rs_PI("PT_Ins_Active").Value = 0
rs_PI("PT_Ins_Inactive_Date") = Now()
rs_PI("PT_Ins_Deactivating_User") = (Environ$("Username"))
rs_PI.Update

End Sub
The code is now working.

Thanks all for your help I appreciate it.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 18:26
Joined
Feb 19, 2013
Messages
16,705
It would help if you used the code I provided in the context in which you supplied it originally - you removed the with rs loop.
 

FreonIceMan

Registered User.
Local time
Today, 13:26
Joined
May 31, 2011
Messages
19
Hi CJ_London,

I just tried it with your fix and I got the "Run-time error 3251". Once I added the dbOpenDynaset it fixed it.

Code:
Private Sub Command144_Click()
    Dim rs As DAO.Recordset
    Set rs = CurrentDb.OpenRecordset("dbo_Patient_Insurance")
    If rs.RecordCount <> 0 Then
        With rs
            .FindFirst "PT_Ins_ID = " & Me.txt_PT_Ins_ID
            If Not .NoMatch Then
                .Edit
                    .Fields("PT_Ins_Active").Value = 0
                    .Fields("PT_Ins_Inactive_Date") = Now()
                    .Fields("PT_Ins_Deactivating_User") = (Environ$("Username"))
                .Update
            End If
        End With
    End If
End Sub
 

Users who are viewing this thread

Top Bottom