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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Force user to input 2 rows of data

Status
Not open for further replies.

rob77

Technical User
Apr 10, 2003
4
GB
I am trying to force users into inputting 2 rows of data into a form, once they have pressed the exit button I don't want the form to close i want the user to be able to input more data on to a blank form.

I've never used DCount before as I am new to the VB side of Access but this is what i've tried (and several variations!)....

Private Sub ExitButton_Click()

Dim Count

If Count(DCount("[StaffOrChildID]", "dbo_EmergencyContacts")) = 2 Then
MsgBox ("You Need to Input Another Emergency Contact")
End If

End Sub
 
Hey Rob,

If you don't want them to exit the form, you may want to use the form_unload event and set cancel based on the value returning 2.

Otherwise you don't need the count() function when you are using the DCount, but you may need to add a filter to select the appropriate records if this is not a temporary table. Also test if DCount is less than 2

Code:
Private Sub Form_Unload(Cancel As Integer))
If DCount("[StaffOrChildID]", "dbo_EmergencyContacts", "[StaffOrChildID] = " & me.StaffOrChildID) < 2 Then
     MsgBox ("You Need to Input Another Emergency Contact")
     cancel=true
End If
End Sub

Stix 42
Long Live Rock and Roll
Pop is for drinking
 
Thank you very much for you help it's much appreciated but it's now erroring, i've added the above line but it then comes up with a runtime error '2001' you cancelled the previous operation Cancel or Debug, on pressing Debug it has a problem with the DCount line, i've checked the spellings are correct for the column name and the table name and they are. Would the problem be caused if the StaffOrChildID is a ComboBox?
 
Is the fieldname StafforChildID?
DCount( FieldName, Table, Filter)

The "*" will work in counting records as well.

If DCount("*", "dbo_EmergencyContacts", "[StaffOrChildID] = " & me.StaffOrChildID) < 2 Then
MsgBox ("You Need to Input Another Emergency Contact")
cancel=true
End If

Maybe post your code so we can see where the problem is.

Stix 42
Long Live Rock and Roll
Pop is for drinking
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top