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

restrict form to new records only

Status
Not open for further replies.

jalgier

Programmer
Nov 7, 2001
15
US
Greetings,

I have a bound form (which houses a subform) and I want to restrict it to only entering new records. I have set Record Selector and Navigation to 'no' on the form's properties. The form is set to open on a new record. Everything would be perfect except that on my mouse is one of those roller wheels. When you use it, it scrolls through all the other records. Is there any way to prevent this? I have some validation built into the code based on field values that won't work once you move to another record. I tried using an unbound form, but I couldn't get the subform (which is in datasheet view) to work properly. Any ideas? Thanks in advance.
 
Open the Form properties dialog. Take a look at the Allow Edits and Data Entry value. Those should control the behavior you're looking for.

Dave Robinder, MCSD
 
Thank you for the response, but unfortunately it didn't have the effect I am looking for. When I open the form, it opens to a new record, but I can still scroll through all the other records using the wheel on my mouse. I just want the user see the new record and be forced to use the buttons I have created (none of which allow them to navigate...just 'Add New','Delete' and 'Exit'). Basically my form works the way I want it to except for the mouse wheel. Is there a way to keep the form only on the current record?
 
Hi,

Don't understand what type of mouse you have but are you sure the DataEntry property on the Mainform is set to YES?

ZaZa
 
OK, I changed Data Entry to 'Yes' and we are getting closer. While I can no longer scroll through previous records, I can still scroll to the next potential record. This unfortunately still bypasses my code validation for my "required" fields. I have three fields which need to be entered (although not required in the table). My validation is in the code on certain events, none of which are covered when a user goes to a different (or in this case, new) record.

My mouse has a wheel (I'm not sure what the correct term is) between the left and right buttons which allows you to scroll (up and down) the page you are on (especially helpful on the web). This is what is causing my headaches.
 
The other possible solution would be to use an unbound form. Since there are no records, the mouse wheel is negated. You will need to manually insert the record using the VBA code behind the form.

Or, you could just ignore the mouse wheel. Users shouldn't run into the issue very often. It's usually just the testers that find something like that (at least it was for us!).

Dave Robinder, MCSD
 
Hi,

I'm no expert but with the data entry property set to yes you will see a blank main form with no previous records.

You will only be able to create new records. It seems that you want to stop the user from moving to ANOTHER new record before completing the present record that they are working on.

If so, try going back to the table that the form was based on and for the fields that you need filled in , go to the properties section and make sure that the REQUIRED property is set to yes.

Hope this helps,
ZaZa

I just tried it on one of my forms. When I try to move to another new record without filling in the "required" fields, access stops you and tell you that it has to be filled in.

 
Hey,

I don't know the answer to your question, but I read something interesting in your explanations. ie to make a field on your form "required".

Could you provide tek-tips with some code how you have done this ?

Regards,

PDTit
 
Sure,

Basically what I am checking for is data in three of the fields on my form. I created a function that I call throughout the code (OnClick of 'Add New' and 'Exit' buttons for example). The function looks something like this...

Dim intVar as Integer 'global variable

Function CheckFields()

If IsNull(Me.Field1) or Me.Field1 = "" then
MsgBox ("You must enter a value in Field1")
Me.Field1.SetFocus
intVar = 0
Else
If IsNull(Me.Field1) or Me.Field1 = "" then
MsgBox ("You must enter a value in Field1")
Me.Field1.SetFocus
intVar = 0
Else
If IsNull(Me.Field1) or Me.Field1 = "" then
MsgBox ("You must enter a value in Field1")
Me.Field1.SetFocus
intVar = 0
End If
End If
End If

In the code, on an event is where I call the function...

cmdExit OnClick()
CheckFields
If intVar = 0 then
intVar = Null 'resets the global variable
Exit Sub
End If
'...continue with code

Hopefully this helps...I'm still learning so this may not be the most efficient code, but it works for me.

 
jalgier,

I'm thinking that if you put this code on the BEFORE UPDATE event FOR THE FORM ,it will force the user to fill in your required fields before they can go to another record.


ZaZa
 
ZaZa is right. But you're also going to have to add a 'Cancel = True' line to each part of the if statement that's catching a problem. Otherwise you'll still end up on a new record. The 'Cancel = true' is necessary to return from the before update event so that Access cancels the update and leaves you on the same record. -- Herb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top