Solved Access cannot find the specific record in a related table when creating a new record via form (1 Viewer)

theDBguy

I’m here to help
Staff member
Local time
Today, 09:03
Joined
Oct 29, 2018
Messages
21,468
Taking a quick lunch, but to answer your question. That's what I tried first and it feels like it was doing the same thing but getting a different error. I'll try in a minute.
If you can post a sample copy of your db with test data, we can help you better/faster (maybe).
 

JMongi

Active member
Local time
Today, 12:03
Joined
Jan 6, 2021
Messages
802
I'm going to post a sample DB. But in creating it, I ran through the code and the changing it to Me.OpenArgs DOES work. Now I get a debug.print of the value but an error on the last line to assign the value "you can't assign a value to this object"
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:03
Joined
Oct 29, 2018
Messages
21,468
I'm going to post a sample DB. But in creating it, I ran through the code and the changing it to Me.OpenArgs DOES work. Now I get a debug.print of the value but an error on the last line to assign the value "you can't assign a value to this object"
Probably seeing the sample db would help rather than guess... I'll wait...
 

JMongi

Active member
Local time
Today, 12:03
Joined
Jan 6, 2021
Messages
802
Here is the sample database. I imported just the necessary tables/queries/forms for this particular app.
 

Attachments

  • SampleHrTrackerDB.accdb
    1.1 MB · Views: 112

theDBguy

I’m here to help
Staff member
Local time
Today, 09:03
Joined
Oct 29, 2018
Messages
21,468
Here is the sample database. I imported just the necessary tables/queries/forms for this particular app.
Hi. Thanks. Looks like you have more than one value you need to auto-assign to the Hours form. When I get past the ProjID, I get this other error.

Code:
You cannot add or change a record because a related record is required in table 'ProjTaskTypes'.
 

JMongi

Active member
Local time
Today, 12:03
Joined
Jan 6, 2021
Messages
802
Hmm...let me start looking at the sample DB in more detail...
Edit: you probably figured it out already but the starting form is FrmProjList
 

Minty

AWF VIP
Local time
Today, 17:03
Joined
Jul 26, 2013
Messages
10,371
Use the form Load event to set control values, certain controls and properties aren't available at On Open.
 

JMongi

Active member
Local time
Today, 12:03
Joined
Jan 6, 2021
Messages
802
Since you got past the assigning of the value, I can't quite follow where you are at. But...
That information (record in project task types) shouldn't be changing. That information should selected by the combobox on FrmAddProjHours. It's recordsource is QryProjTaskLookup and should store the value in TaskIDFK.
 

JMongi

Active member
Local time
Today, 12:03
Joined
Jan 6, 2021
Messages
802
Use the form Load event to set control values, certain controls and properties aren't available at On Open.
That's ironic, I picked OnOpen because I thought that was the better place to make these changes and because that's the example MS used. Lol.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:03
Joined
Oct 29, 2018
Messages
21,468
Since you got past the assigning of the value, I can't quite follow where you are at. But...
That information (record in project task types) shouldn't be changing. That information should selected by the combobox on FrmAddProjHours. It's recordsource is QryProjTaskLookup and should store the value in TaskIDFK.
Okay, I made a minor adjustment by using the Default Value property instead. See if this works for you.
 

Attachments

  • SampleHrTrackerDB.zip
    416 KB · Views: 119

JMongi

Active member
Local time
Today, 12:03
Joined
Jan 6, 2021
Messages
802
Investigating...Ok. I see what you mean:
Code:
Me.ProjIDFK.DefaultValue = ProjIDFKv
It also looks like you defined the second variable as the proper type to use as the ID since is should be a number not a string and used CLng to convert to a long integer.
Then the Nz is to protect CLng from trying to convert a null value.
P.S. Thanks for adding the save code, never got around to it...Ha!
 
Last edited:

JMongi

Active member
Local time
Today, 12:03
Joined
Jan 6, 2021
Messages
802
Things seem to be working nicely. Thanks! I've got other wrinkles, but I'll create a separate thread if I need to ask another question.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:03
Joined
Oct 29, 2018
Messages
21,468
Things seem to be working nicely. Thanks! I've got other wrinkles, but I'll create a separate thread if I need to ask another question.
Hi. Glad to hear you got it sorted out. Good luck with your project.
 

JMongi

Active member
Local time
Today, 12:03
Joined
Jan 6, 2021
Messages
802
I see light at the end of the tunnel. Let's hope it's not a train! ;)
 

Users who are viewing this thread

Top Bottom