Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Not finding the form that's open. Umbane?

Status
Not open for further replies.

katiekat

Technical User
Jun 6, 2000
300
US
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"
    If DLookup("[company_id]", "[businessaddress]=", "[company_id]=" & Forms![BusinessInformation]![Company_ID]) Then
    
    strlinkcriteria = "[company_id]= forms![BusinessInformation]![company_id]"
    
    DoCmd.OpenForm stDocName, , , strlinkcriteria
    DoCmd.Requery
    
    Else
    DoCmd.RunCommand acCmdSaveRecord
    DoCmd.OpenForm stDocName, , , , 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

It's telling me that it can't find the form "BusinessInformation" I have tried everything to change it so the thing will recognize it. The only think I can think, (other than I screwed the code) is that it doesn't like that it's open. But that doesn't make sense! I hope someone can help. I am just doing this all wrong.
 
Oh yeah, this is code for a button to open a form from another form. When this happens either it finds info that is already there, or it fills in the company Id for you so you don't have to do it.

just in case anyone was wondering.

Thanks lovely people that help me!
 
If you are opening the address form from the business information form, try replacing Forms![BusinessInformation]![Company_ID] with me.company_id

Mike Rohde
rohdem@marshallengines.com
 
Also, is company_id declared as number or text?

Mike Rohde
rohdem@marshallengines.com
 
I have been remiss in checking here! Darn! You probably aren't looking anymore, but the ID is text.

Here's this. My main problem right now is that it thinks that it can't find the form form that I am opening the other form from. yikes! That was confusing! I hope it made sense....

Code:
Private Sub Command66_Click()
    
    Dim strlinkcriteria As String
    Dim stdocname As String
    stdocname = "businessaddress"
    
    If DLookup("[company id]", "[businessaddress]", "[company id]=" & Forms![businessinformation]![Company ID]) Then
    strlinkcriteria = "[company id]=forms![businessinformation]![company id]"
    DoCmd.OpenForm stdocname, , , strlinkcriteria
    DoCmd.Requery
    
    Else
        DoCmd.RunCommand acCmdSaveRecord
        DoCmd.OpenForm stdocname, , , , acAdd, , Me![Company ID]
End If

End Sub
 
I'm a little confused as to how you are determining if information already exists.....you have a dlookup statement in your if clause, but there is no comparison, i.e.

if dlookup = something then
do something
end if

Shouldn't you check to see if the dlookup is null??

If Not IsNull(DLookup("[company id]", "[businessaddress]", "[company id]=" & Forms![businessinformation]![Company ID])) Then
strlinkcriteria = "[company id]=forms![businessinformation]![company id]"
DoCmd.OpenForm stdocname, , , strlinkcriteria
DoCmd.Requery

Else
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenForm stdocname, , , , acAdd, , Me![Company ID]
End If

Mike Rohde
rohdem@marshallengines.com
 
Thoughts...

businessaddress should not be in brackets as it is a table vs a field.

Or am I wrong???


Mary :eek:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top