Link to home
Start Free TrialLog in
Avatar of CptPicard
CptPicardFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Form Complete Status

Hi - I feel this is easy but rather complicated to explain.

firstly, I'm using Access 2010.

I have two tables called tbl_contacts & tbl_questions

I have two forms called frm_questions1 & frm_questions2

The record source for both the above forms is from tbl_questions.  At the top of the form, I've got a section for 'Contacts'.  This basically allows me to choose a name from a drop down box and it automatically completes all the other fields about this person that are stored in the 'tbl_contacts' table.  This way I don't have to type the persons details in each time.  

As mentioned above, I've created two forms.  'frm_questions1' & 'frm_questions2' that share the same record source. (It's important they are in two separate forms which look different from one another).

On the first form 'frm_questions1' I have two buttons which say;

- 'Click here to complete questions 1'  
- 'Click here to complete questions 2'  

I would like to have a status appear underneath these buttons that show if these forms have been completed or not.

So, if all the values in question 1 get completed it will display a label under this button for 'Questions 1', saying 'Complete'.  If the questions haven't been started or are incomplete, then it will display a message saying 'Incomplete'.

The same applies for 'Questions 2'.

If you're able to give me an example to which I can tweak for my own application that will be very helpful.

Hope this makes sense. Happy to clarify more...
Avatar of als315
als315
Flag of Russian Federation image

You can, for example, count Null values in answers.
Something like:
IIF(dcount("*", "Form's recordsource", "isnull(Answer)")>0, "Incomplete", "Complete")
Avatar of CptPicard

ASKER

Hi - the problem is that it's two forms sharing the same record source.  So the first form would populate half the table and the second form will populate the other half.  Thus if I use the above, it will look to see if the entire table has been completed.    Which is why I'm guessing the best way would be to include each text field and check box somehow within the code to see if it's been completed.

I can get it to work for the first form because I've set the on current event to

Me.lblquestion1comp.Visible = (DCount("*", "tbl_questions1", "contact_id = " & Nz(Me.contact_id, -1)) > 0)

Me.lblquestion1incomp.Visible = (DCount("*", "tbl_questions1", "contact_id = " & Nz(Me.contact_id, -1)) = 0)

This checks to see if this particular field has been completed or not.  If it has, it will display the 'Complete' label. If it hasn't, it will display the 'Incomplete' label.

But I can't seem to get the status label to display 'Complete' or 'Incomplete' under the button for 'Questions 2'.  

I thought about passing a value to a hidden field when the form is opened.  Therefore, if a value is entered into this field, the code would execute to display the status 'Complete' and hide the status 'Incomplete' under the button 'Questions 2'.  Would be better if it was to check all fields but I'm not sure how that would be possible with multiple choice questions.
I've not heard anything back so I've decided to change the way it should work to make it less complicated.

I now have 2 tables and 1 form.

On the form I have two buttons and 4 labels. 2 labels under each button on top of each other, but I want only one of these labels displayed under each button.  The labels are; 'complete' & 'Incomplete'

If there's a value and it's associated with the Contact_ID in table 1 and 2 then it will display the label 'Complete'.  If there's no value (Contact_ID) entered into these tables, then the label will display 'Incomplete'.

Here's an example of what I've got which doesn't work properly.

Private Sub Form_AfterUpdate()

If Me.lblComplete.Visible = (DCount("*", "tbl_1", "Contact_ID = " & Nz(Me.Contact_ID, -1)) > 0) Then
Me.lblComplete.Visible = True
Me.lblIncomplete.Visible = False
End If

If Me.lblComplete.Visible = (DCount("*", "tbl_1", "Contact_ID = " & Nz(Me.Contact_ID, -1)) = 0) Then
Me.lblComplete.Visible = False
Me.lblIncomplete.Visible = True
End If

End Sub

It's important that when it's looking in the 2 different tables that it's looking for and associating the correct Contact_ID, otherwise it's pointless.   So if it can find the same Contact_ID it will display the 'Complete' label on the form and if it can't find the Contact_ID it will display the 'Incomplete' label on the form.

Hope this makes more sense.
Can you upload sample DB?
Not really, that's a bit difficult as I can't upload it as it is and it'd take a long time to change it to make it suitable to upload to the web.
You should start from testing of dcount. Add button to your form and add code to it:
Dim n as long
n = DCount("*", "tbl_1", "Contact_ID = " & Nz(Me.Contact_ID, -1))
msgbox n
Test result for completed and incompleted questions
I've created two buttons and put the above code in the 'on click' event and changed the table name in the code above to look at both tbl_1 and tbl_2 respectively.  If I have the same Contact_ID in table 1 and table 2 then both buttons will prompt '1'.  If I have only the same Contact_ID in tbl_1 then it shows '1' for the first button and '0' for the second button.  So I assume this works fine.
Hi Als315.  What's next :)
ASKER CERTIFIED SOLUTION
Avatar of als315
als315
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you for your time.