VBA Dlookup Type Mismatch

steve21nj

Registered User.
Local time
Today, 03:12
Joined
Sep 11, 2012
Messages
260
Hello,

I am having an issue with my vba while following Dev Ashish's site http://access.mvps.org/access/general/gen0018.htm

My Dlookup works correctly, from what I have tested. The issue comes from when I run the update query after, it updates every record instead of the current record. Can anyone point me in the right direction?

The after update vba: (keep in mind MemberID is a text field)
Code:
Private Sub Combo59_AfterUpdate()
Response = MsgBox("Do you want update this individuals program?", vbYesNo + vbQuestion, "Update Program")
 
If Response = vbYes Then
 
    If DLookup("MemberID", "tblMemberProgram", "[MemberID] = '" & [Forms]![FRM_Member_Stats].[MemberID] & "'") > 0 Then
        'MsgBox "Record exist"
       DoCmd.OpenQuery "UpdateProgram"
    Else
        MsgBox "Record does not exist"
      '  DoCmd.OpenQuery "AppendProgram"
    End If
End If
End Sub

Update Query
Code:
UPDATE tblMemberProgram SET tblMemberProgram.ProgramOffice = [Forms].[FRM_Member_Stats].[Combo59];

Do I need to run the dlookup in the update query to limit to the specific record based on the form?
 
think I figured it out unless someone has a better response...


Code:
UPDATE tblMemberProgram SET tblMemberProgram.ProgramOffice = [Forms].[FRM_Member_Stats].[Combo59]
WHERE ((([Forms].[FRM_Member_Stats].[Text44])=[tblMemberProgram].[MemberID]));
 
Then it brings me to my next issue on the append side...

When I append the current record, it sees that the table has 3 records, and adds 3 of the same current record. So then it has 6 records in the table. If I run it again, it adds 6 records and so on.

Code:
INSERT INTO tblMemberProgram ( MemberID, ProgramOffice )
SELECT [Forms].[FRM_Member_Stats].[Text44] AS Expr2, [Forms].[FRM_Member_Stats].[Combo59] AS Expr1
FROM tblMemberProgram;
 
Thanks for the help. My end product.

Append
Code:
INSERT INTO tblMemberProgram ( MemberID, ProgramOffice )
SELECT [Forms]![FRM_Member_Stats].[Text44] AS Expr1, [Forms]![FRM_Member_Stats].[Combo59] AS Expr2;

Update
Code:
UPDATE tblMemberProgram SET tblMemberProgram.ProgramOffice = [Forms].[FRM_Member_Stats].[Combo59]
WHERE ((([MemberID] = [Forms].[FRM_Member_Stats].[Text44])));
 

Users who are viewing this thread

Back
Top Bottom