New blank record being added (1 Viewer)

lscheer

Registered User.
Local time
Today, 00:24
Joined
Jan 20, 2000
Messages
185
I have a module that runs when I check a checkbox that adds the existing record to a second table (1-1 relationship). It works just fine except that when I return to the master form, there is a new blank record that has been added after the one that I checked the box for. Any ideas why this is happening? Here is the code (a converted macro):


Function mcrAddApplicant()
On Error GoTo mcrAddApplicant_Err

DoCmd.OpenForm "frmApplicants", acNormal, "", "", acEdit, acNormal
DoCmd.GoToControl "ApplID"
DoCmd.FindRecord Forms!frmContacts!ContactID, acEntire, False, , False, acCurrent, True
If (Forms!frmContacts.ContactID <> Forms!frmApplicants.ApplID) Then
DoCmd.GoToRecord acForm, "frmApplicants", acNewRec
Forms!frmApplicants!ApplID = Forms!frmContacts!ContactID
DoCmd.Requery ""
DoCmd.GoToControl "ApplID"
DoCmd.FindRecord Forms!frmContacts!ContactID, acEntire, False, , False, acCurrent, True
End If
DoCmd.Close acForm, "frmContacts"


mcrAddApplicant_Exit:
Exit Function

mcrAddApplicant_Err:
MsgBox Error$
Resume mcrAddApplicant_Exit

End Function
 

the_net_2.0

Banned
Local time
Yesterday, 18:24
Joined
Sep 6, 2010
Messages
812
you're opening the apps form, then at the end, closing the contacts form. so I assume the apps form is still open when this all ends?

if that is so, the reason for the new rec is probably because you're telling the program to go to a new record via:
Code:
DoCmd.GoToRecord acForm, "frmApplicants", acNewRec
hence, you're seeing it.
 

lscheer

Registered User.
Local time
Today, 00:24
Joined
Jan 20, 2000
Messages
185
If I close the contacts form before adding the new record to the apps form then the code can't reference the ContactID field for the If/then statement. Any ideas on how to adjust the code to make it work properly?
 

boblarson

Smeghead
Local time
Yesterday, 16:24
Joined
Jan 12, 2001
Messages
32,059
I believe that your Requery of the form may be the culprit, especially if you have anything set as a value in the new record like:
Forms!frmApplicants!ApplID = Forms!frmContacts!ContactID

So, what happens if you comment out the DoCmd.Requery line?

Also, I would be interested to see a screenshot or two of what forms you are talking about and how they interact (or a better description of exactly what you are aiming at) because looking at your code I think there may be better ways of accomplishing what you want but I'm not too clear on what it is you want.
 

lscheer

Registered User.
Local time
Today, 00:24
Joined
Jan 20, 2000
Messages
185
boblarson,
Thanks for your suggestion, however it didn't seem to help. The blank record is still added to the Contacts form. I did try playing with something else and that was setting the DoCmd.GoToRecord acForm, "frmApplicants", acNewRec to acNext instead of acNew and that seems to have worked, but again, I'm not sure if that is actually the best way to do this. (By the way, when I comment out the Requery command, the nuts and bolts of the code still work, but since it functions to actually display the data in the form for the record that was added, when it doesn't requery, the form appears blank to the novice user which is why I added it in the first place).

I'm attaching a screenshot of the main form as well as the table relationships; I'm not sure what additional screenshots would help. Basically, what happens is the Contacts Form houses our master list of contacts and tracks basic contact information. When I check the "Applicant" boxes, the code is supposed to add the current Contacts record to the Applicant's form/table. This is because the Applicants have additional information and relationships (specifically 1-many for which courses they have applied for). The code is supposed to check to see if the person is already in the Applicant's table and if so, go to their record; if not, to add them to the underlying table.

Thanks again~!
 

Attachments

  • Slide1.JPG
    Slide1.JPG
    33 KB · Views: 86
  • Slide2.JPG
    Slide2.JPG
    88.9 KB · Views: 102

Users who are viewing this thread

Top Bottom