Solved Update field in table with value in Combobox (1 Viewer)

Momma

Member
Local time
Today, 10:04
Joined
Jan 22, 2022
Messages
114
Hi
I'm slowly trying to get into vba but I need help, please.
I'm trying to update the DefaultVetID field in tblDefaultVet to the value of the Combobox in the form frmSelectVet. This is done in the After Update event of the Combobox but the reference to the Combobox is incorrect.
The value needs to be passed on to a text field, DefaultVetID, in the report rptHealthClearance. I currently do this with a DLookup command from the text field in the report called.
I then have a DLookup command in the PracticeName, Address & Telephone fields using the value in the DefaultVetID as the record source to get the values for the specific record.

I've attached my database file. Hope this makes sense.
Thank you in advance 🤗


Code:
Private Sub CboVet_AfterUpdate()

        DoCmd.RunSQL "UPDATE tbldefaultvet SET [Defaultvetid] = cbovet.column(0)"

End Sub
 

Attachments

  • TestDB.accdb
    632 KB · Views: 248

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 20:04
Joined
May 21, 2018
Messages
8,527
I do not know what you are doing, but it is definitely wrong and does not make any sense.
If you are trying to assign the default vet then you need to bind the form to tblDefaultVet not tblVet. Then the combo is bound to the field default vetID. No need for any code.
 

GPGeorge

Grover Park George
Local time
Yesterday, 17:04
Joined
Nov 25, 2004
Messages
1,863
This is only partly a VBA problem. I made several corrections in the form and report, and added a subreport for the vet to replace the lookups.
 

Attachments

  • TestDB2020309.accdb
    712 KB · Views: 250

MajP

You've got your good things, and you've got mine.
Local time
Yesterday, 20:04
Joined
May 21, 2018
Messages
8,527
Sorry that still makes no sense. There is no need for any code, the form is bound to the wrong table.
 

Momma

Member
Local time
Today, 10:04
Joined
Jan 22, 2022
Messages
114
This is only partly a VBA problem. I made several corrections in the form and report, and added a subreport for the vet to replace the lookups.
Thank you GPGeorge, the result is exactly what I want. I still have a lot to learn, hope I'll get there one day 😊
 

GPGeorge

Grover Park George
Local time
Yesterday, 17:04
Joined
Nov 25, 2004
Messages
1,863
Thank you GPGeorge, the result is exactly what I want. I still have a lot to learn, hope I'll get there one day 😊
We all started in the same place. You will get there.

Good luck with the project.
 

Users who are viewing this thread

Top Bottom