Force form field to show specific table value (1 Viewer)

JoeBruce

Registered User.
Local time
Today, 17:17
Joined
Jan 13, 2017
Messages
32
I have tried a few options but keep getting this: :banghead:

I have a form for entering service information. But there is one service slightly different than the others, so I created a different form. My struggle is getting this second form to automatically show this specific service in the form field.

The closest I've come is using a combo box and basing the row source off a query which only returns the one service. So you can only select that specific service. But I would rather it just be a locked text box that displays the value (the specific service) any time I go to a new a record on the form.

I have tried using the "Default Value" field in the form properties, using SQL statement to return the value, and using DLoookup to return the value. I thought I could do it with DLookup, but: :banghead:
 

theDBguy

I’m here to help
Staff member
Local time
Today, 16:17
Joined
Oct 29, 2018
Messages
21,358
Hi. I think you're on the right track. You can use the Default Value to automatically assign a value to a field or control. You can also use a DLookup() expression as a Default Value. So, to help you figure out why what you're trying to do is not working, we'll have to see it. Are you able to post a sample db?
 

JoeBruce

Registered User.
Local time
Today, 17:17
Joined
Jan 13, 2017
Messages
32
Actually, I believe you got me my solution. I didn't think to use the DLookup in the Default Value field. Initial testing seems to work, now I just need to fine tune the presentation of it. Much obliged!

I'll report back my future success or frustrations...

EDIT: Yes, I put the DLookup function into the Default Value property of my original combo box. Then I got rid of all the excess stuff I had done on the form and in VBA trying to make it work. This way the value still gets assigned to the record as needed. (DLookup is used to assign a primary key as default value, and the box's control is its partner foreign key, and the row source stays the same to display the necessary text.) All is well (until the next bug is discovered)!
 
Last edited:

theDBguy

I’m here to help
Staff member
Local time
Today, 16:17
Joined
Oct 29, 2018
Messages
21,358
Actually, I believe you got me my solution. I didn't think to use the DLookup in the Default Value field. Initial testing seems to work, now I just need to fine tune the presentation of it. Much obliged!

I'll report back my future success or frustrations...
Hi. Nice work! Glad to hear you got it sorted out. Good luck with your project.
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 19:17
Joined
Feb 19, 2002
Messages
42,977
I would not have created a separate form. If the services are so different that you need a second form and all the code that goes along with that, then you have a design flaw. What EXACTLY is the difference between the two types of services? Perhaps adding a service type column to the Service table would simplify your code.
 

Users who are viewing this thread

Top Bottom