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

Opening form in add mode? 1

Status
Not open for further replies.

Egglar

Technical User
Apr 4, 2002
88
GB
Very noobie question here, ive been searching google and this forum for ages but cant find an answer to this amazingly simple problem, I know it can be done from a switchboard/front end menu.

I just want a basic input form, that when is opend will be in add mode only, and not show any previous/existing records.

I would prefer it in VB but im open to all suggestions!

Thanks in advance, Elliot
 
Elliot,

Quite simply done. Go into the form in design view, view the properties of the form via the View, Properties menu options. Find the property called called 'Data Entry', and set its value to 'Yes'. Then save the form. The data entry mode will be retained in the form.

This will set the form to data entry mode, and only allow the addition of new records, without making visible existing ones.

If you need the form to be flexible and change its mode between data entry and non data entry mode, then this can be done programmatically. Let us know if this is a requirement.



Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
(dont cut corners or you'll go round in circles)
 
Thanks for your quick reply!

Thats fine, ive removed the record selectors too which helps. I new it was a simple form property but i couldnt find it!

Thanks Again.
 
While ive got a thread going i may as well ask my other question,

Ive got a data entry form, with Save, Clear and Close buttons. The problem is, as soon as a user enters one record, and hits the save button, the form creates the a new record the on click property of the save button is

Call DoCmd.RunCommand(acCmdSaveRecord)
DoCmd.GoToRecord , , acNewRec

If the user then clicks close, the form has already created a new record by clicking save, and it ends up being blank.

Any suggestions around this?

Thanks, Elliot.
 
Well normally, you would have manditory fields associated with the definition of the form's underlying record, and a save would fail if these were not entered.

A simple example of programming to detect an incomplete record would be to put the following 'conditional' code around your existing lines. I'll assume you have a field on the form called txtYourField which should contain some form of value.
[tt]
if not isnull(me!txtYourField ) then
Call DoCmd.RunCommand(acCmdSaveRecord)
DoCmd.GoToRecord , , acNewRec
else
msgbox "You have not entered manditory data. Record not saved."
endif
[/tt]
There are better ways to validate your data; typically this is done on the "BeforeUpdate" event of a form, but I may be jumping the gun a bit here on your learning curve. Give the above a try first, and make sure you understand it OK.
Good luck,


Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
(dont cut corners or you'll go round in circles)
 
Well, i have mandatory data checking in afterupdate and lostfocus properties, eg:

Private Sub txtRef_LostFocus()
If txtRef.Text = "" Then
MsgBox ("Please enter a payment reference")
txtDate.setfocus
txtRef.setfocus
End If
End Sub

And also a function that looks up text from a txt box in a field from a table, and if it doesnt exist it alerts the user. (using the dlookup function).

I prefer this sort of data checking to happen when a user leaves or updates a text box, but it looks like i may have to restructure my code to do it as the user trys to save the record.

But it still gives the problem that, if the user enters all the correct data and wants to save the record, he/she hits save and that data is saves to the table, and at that same point the "DoCmd.GoToRecord , , acNewRec" creates a new record, but suppose the user doesnt want to enter another new record and just wants to close it, By clicking the close button, its still leaving the blank record in the database.

I suppose this could be achieved by having a msgbox asking if they want to add a new record or close, but this will be increidabley annoying when the user has 100 or 200 records to enter.



 
LostFocus event may be the wrong place to put the check; it assumes the user gives focus to this field in the first place; he/she may not!

The two lines of code:
[tt]
Call DoCmd.RunCommand(acCmdSaveRecord)
DoCmd.GoToRecord , , acNewRec
[/tt]
would only create the new record if you actually enter something into the new row. If the last row just has a * next to it in the underlying table, its a record awaiting entry, but is not yet registered as a record in the table, if you know what i mean. Its possible that you have some other code doing things to effect the fields on the form.


Steve Lewy
Solutions Developer
steve@lewycomputing.com.au
(dont cut corners or you'll go round in circles)
 
Ive now re coded all the error checking to the save button, this works much better!

But as you suggest, i do have code doing things to effect other fields in the form, such as default date, and an option group that has a vlaue either 1 or 2, so, data is in the record as soon as a new one is created.

I could wirte a piece of code that determines whether certain text boxes are blank and if so deletes the record, and put it in the close cmd button. This would then delete the record that has just been created. It would also be ok as the text boxes that i would reference are mandatory in the save button, so the user will be unable to close and therefore delete a record that is wanted, this could also be backed up by a "you cannot close this form when the Reference field contanis text, if you want to save this record then press save, otherwise delete the text and press close" message.

Is this the best way of doing this?

Thanks, Elliot
 
Steve,
I read this thread 702-548238 and noticed your comment.

"If you need the form to be flexible and change its mode between data entry and non data entry mode, then this can be done programmatically."

Can you please follow up with this? How do I check if the >* button for adding new record was clicked? I need to clear some unbound fields. They display the result of a calculation and need to be set to $0.00 when new data is entered. Thank you.
 
Steve, I am with Xuanb. I also need the code for adding new records or editing records. Actually, I don't mind if it show all the old records, but when I open a form I want it always to go to a new record at the end of all the records. Thanks in advance, Janet Lyn
 
Xuanb, after I left my last thread I continued on in researching my problem. I found the following thread which might help your situation. Thread702-573277. Good luck. Janet Lyn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top