Trouble with onClick (1 Viewer)

hardhitter06

Registered User.
Local time
Today, 05:19
Joined
Dec 21, 2006
Messages
600
Hi All,

I have a database with two tables and two forms.

FormA arrives prior to a Contract. FormB arrives post Contract.

FormA and FormB are actual names of forms in our office.

ContractNo is the FK for both.

On my dashboard, I have a search for FormA. When clicking the command button, a dialog window pops up asking for a Contract No. The user enters the contract number and if that contract No. is in the FormA table it will return a FormA record. (this works)

On this form that opens, I then have a button that is designed to search for a Form B with that same Contract No. I have this code:

Code:
Private Sub Command56_Click()
 If DCount("*", "FormB", "ContractNo = '" & Me.ContractNo & "'") = 0 Then
        If MsgBox("The Contract Number you are searching has no Form B entry." & vbCrLf & vbCrLf & _
                    "Do you wish to add this record?", vbQuestion + vbYesNo) = vbYes Then _
            DoCmd.OpenForm "FormBInput", DataMode:=acFormAdd, OpenArgs:=Me.ContractNo
            Else
        DoCmd.OpenForm "FormBSearch", WhereCondition:="ContractNo = '" & Me.ContractNo & "'"
    End If
End Sub

What I'm trying to accomplish is if there is a ContractNo from the first search (the FormA search) that matches a record in the FormB table, to display this record on the FormB form I created.

If the FormB doesn't exist for that Contract No, to open a blank input form for FormB.

This isn't working and I'm not sure why. I click the button knowing there is a Form B with that same contract No. but it returns a blank form.

I will attach a zipped file of my DB because this may be confusing.

Thank you.
 

Attachments

  • FormAB.zip
    360 KB · Views: 70

bob fitz

AWF VIP
Local time
Today, 10:19
Joined
May 23, 2011
Messages
4,726
I can only work with files in A2003 mdb format. If you can post a copy I will take a look. In the meantime, have you considered having form "B" as a subform on the "A" form.
 

hardhitter06

Registered User.
Local time
Today, 05:19
Joined
Dec 21, 2006
Messages
600
Attached (if i did it right?)

Also, Form B has a subform. Form A and Form B are seperate other than that sharing Contract No.

Form B and SubFormB share a lot of fields hence why I created a subform there.
 

Attachments

  • FormAB (2).zip
    96.6 KB · Views: 65

hardhitter06

Registered User.
Local time
Today, 05:19
Joined
Dec 21, 2006
Messages
600
Thanks Bob for the link, here ya go.
 

Attachments

  • FormAB2003verision.zip
    93.3 KB · Views: 65

Users who are viewing this thread

Top Bottom