This is what I want to happen: I open a form. I enter customer information. I then push a button that opens up another form where I enter the address for that company. Now, if there is already an address, the form will open up to the correct reccord. If there is no address, the form will open up with the Key already filled in. Basically, I want it to create a reccord for me if there isn't one there already.
I already asked this question and I got this code in response:
Now, this concept makes sense to me, but I can't get it to work right. I know there is something that I am missing, and I don't know what it is. Here is what I have, with all the stuff filled in.
I know this is really long and annoying, but I would really appreciate any help that I can get. I have been slaving over this for quite a while. Thank you thank you thank you!!
I already asked this question and I got this code in response:
Code:
Dim StrLinkCriteria As String 'Declare the variable StrLinkCriteria
Dim stDocName As String 'Declare the variable stDocName
stDocName = "Section B" 'Define stDocName
'If there is already a record corresponding to the ApplicantID in Section B
'Open the form with that record
If DLookup("[ApplicantID]", "[Section B]", "[ApplicantID]=" & Forms![SECTION A]![ApplicantID]) Then
'Define StrLinkCriteria, open the form in edit mode and requery the source for the form
StrLinkCriteria = "[ApplicantID] = Forms![Section A]![ApplicantID]"
DoCmd.OpenForm stDocName, , , StrLinkCriteria
DoCmd.Requery
'Otherwise open the form in add mode and set the OpenArgs value to the ApplicantID
Else
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenForm stDocName, , , , acAdd, , Me!ApplicantID
Now, this concept makes sense to me, but I can't get it to work right. I know there is something that I am missing, and I don't know what it is. Here is what I have, with all the stuff filled in.
Code:
Private Sub open_address_form_Click()
On Error GoTo Err_open_address_form_Click
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "BusinessAddress"
stLinkCriteria = "[Company ID]=" & "'" & Me![Company ID] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria
If DLookup("[Company ID]", "[businessaddress]", "[company id]=" & Forms![business informaion]![Company ID]) Then
strlinkcriteria = "[company id] = forms![businessinformaion]![company id]"
DoCmd.OpenForm BusinessAddress, , , strlinkcritera
DoCmd.Requery
Else
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenForm BusinessAddress, , , , acFormAdd, , Me![Company ID]
Exit_open_address_form_Click:
Exit Sub
Err_open_address_form_Click:
MsgBox Err.Description
Resume Exit_open_address_form_Click
End If
End Sub
I know this is really long and annoying, but I would really appreciate any help that I can get. I have been slaving over this for quite a while. Thank you thank you thank you!!