Data entry form / Combo box error (1 Viewer)

tlc1974

Registered User.
Local time
Today, 14:16
Joined
Aug 4, 2003
Messages
21
I have created a form with a combo box that looks up information from another table. The form automatically goes to a new record when opened as I am using just for data entry. When trying to close the form I get an error as no information has been entered into the combo box field. How can I get round this as the form automatically goes to a new record after update which I want it to do so people don't have to use the navigation buttons. Thanks in advance.
 

Minty

AWF VIP
Local time
Today, 14:16
Joined
Jul 26, 2013
Messages
10,371
What error is raised , and what code do you have (if any) to close the form?
Do you have a default value for the combo box, or are you setting it in any code?
 

tlc1974

Registered User.
Local time
Today, 14:16
Joined
Aug 4, 2003
Messages
21
Thank you so much for replying. I used the wizard to set the combo box up storing the information in the data entry table. I have an ID autonumber as the primary key for the combo box associated with a name. The name is viewable on the form and the autonumber is being stored in the data entry table. I think the problem is because the form is going to a new record when I try and close it is wanting information filled in. I have tried code to disable the warning message on close but this has not worked as it is still appearing. The message is I must enter a vaule in the combo box field.
 

tlc1974

Registered User.
Local time
Today, 14:16
Joined
Aug 4, 2003
Messages
21
I have just changed the ID to not required in the table so that message no longer appears but I now get you can't save the record at this time error. Is there a way to disable that message?
 

tlc1974

Registered User.
Local time
Today, 14:16
Joined
Aug 4, 2003
Messages
21
I have added a close button onto the form which gets rid of the error message but an extra blank record is being added into the table now.
 

Minty

AWF VIP
Local time
Today, 14:16
Joined
Jul 26, 2013
Messages
10,371
I'm not sure I understand the point or even the possibility of having a combo box for the ID if it's an Autonumber and only ever on a new record?

Surely you can't choose the number on a new record, so I am confused by the intent?

It certainly would explain the errors. Maybe you could explain (in simple non-database terms) the purpose of the form / combo ?
 

tlc1974

Registered User.
Local time
Today, 14:16
Joined
Aug 4, 2003
Messages
21
I have a table with a list of projects the primary key being an autonumber. I have another form to record time using the name of the project and time. The combo box is being used with ID number in both tables so the project name is viewable on the form for ease of allocating time against it. The combo box is for the name not the ID that is just the primary key.
 

Minty

AWF VIP
Local time
Today, 14:16
Joined
Jul 26, 2013
Messages
10,371
So it's the foreign key in the time records then ?

Can you post up a picture of the tables and relationships, I think you may have a problem with the design ?
 

tlc1974

Registered User.
Local time
Today, 14:16
Joined
Aug 4, 2003
Messages
21
Thank you for all your help.
 

Attachments

  • table.jpg
    table.jpg
    15.4 KB · Views: 56

jdraw

Super Moderator
Staff member
Local time
Today, 09:16
Joined
Jan 23, 2006
Messages
15,378
??
a table with a list of projects
..name of the project and time.

You mention Project, but the table is Coop???
 

Minty

AWF VIP
Local time
Today, 14:16
Joined
Jul 26, 2013
Messages
10,371
I'm going to stab a guess that you have included both tables in your forms underlying query, and have made coop.coopid the control source for your combo box...

Which is incorrect.

You need the combo to have a control source of StaffTime.Coopid

I too am slightly baffled by the coop table, which I have guessed is your project table.
 

tlc1974

Registered User.
Local time
Today, 14:16
Joined
Aug 4, 2003
Messages
21
My projects are co-ops and the query only has the staff table behind it. The combo box is looking at the co-op table SELECT [Coop].[CoopID], [Coop].[Coop] FROM Coop but the control source is coopid from the staff table which is why I am confused it is not working.

Thank you for all your help.
 

Minty

AWF VIP
Local time
Today, 14:16
Joined
Jul 26, 2013
Messages
10,371
Okay - sample database time. Can you post up a stripped down zipped version of the database with the offending form, how you get to open it , and some dummy records - enough for us to recreate the problem?
 

tlc1974

Registered User.
Local time
Today, 14:16
Joined
Aug 4, 2003
Messages
21
I have stripped it down to the 2 tables and 1 form including sample data. Thank you again.
 

Attachments

  • Sample.accdb
    536 KB · Views: 58

Minty

AWF VIP
Local time
Today, 14:16
Joined
Jul 26, 2013
Messages
10,371
Okay - a simple fix, add the following to your form load event, you have need to add an important extra word.
Code:
    Me.NameID.[COLOR="Red"]DefaultValue[/COLOR] = VBA.Environ("USERNAME")
Remove the current event code completely.

At the moment by setting this value with the form current event you are creating a dirty record which is then saved when you close the form.

Also remove the Cancel = True from your form close - it's not actually doing anything, as that command button event has no cancel property.

And finally the acSaveNo in this
Code:
 DoCmd.Close acForm, "stafftime", acSaveNo

Is actually for saving form design changes, not the record.
 

tlc1974

Registered User.
Local time
Today, 14:16
Joined
Aug 4, 2003
Messages
21
Thank you for taking the time to look and I will implement the changes. It has been a few years since I touched a database so need to refresh my knowledge.
 

Minty

AWF VIP
Local time
Today, 14:16
Joined
Jul 26, 2013
Messages
10,371
No problem - I can see how that would be difficult to spot if you aren't aware of the way access handles the different events.

Good luck with your project.
 

Users who are viewing this thread

Top Bottom