Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

What am I doing wrong here??

What am I doing wrong here??

What am I doing wrong here??

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:

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
    'Otherwise open the form in add mode and set the OpenArgs value to the ApplicantID
        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.

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.RunCommand acCmdSaveRecord
DoCmd.OpenForm BusinessAddress, , , , acFormAdd, , Me![Company ID]

    Exit Sub

    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!!

RE: What am I doing wrong here??

OK, I'll give it a shot.  

I am assuming that this is the code for the button you push after you work on the company info and want to get to the address.  I am wondering why you have the following lines of code:

stLinkCriteria = "[Company ID]=" & "'" & Me![Company ID] & "'"
    DoCmd.OpenForm stDocName, , , stLinkCriteria

BEFORE you test using the DLookup line???

It would seem to me, and it looks like that was the original suggestion that you got, that the first thing you need to do is to do the DLookup, and then based on that, use the OpenForm command in one of two ways.


RE: What am I doing wrong here??

Thank you Kathryn!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close