Hi. In my form I need to automatically populate the description field by the data that is entered in the code field.
For example: Code = 5710 Description = GOJ
Both the Code and Description fields are in the same table.
Thanks for any help given.
Hi. In my form I need to automatically populate the description field by the data that is entered in the code field.
For example: Code = 5710 Description = GOJ
Both the Code and Description fields are in the same table.
Thanks for any help given.
Make combo box with Code, Description fields. After they select a code, in the AfterUpdate event, use me.Description = me.Code.column(1)
I have too many codes for combo box. They need to be manually entered.
Also, this is in a sub form. I didn't know if that mattered or not.
So you have over 65535 codes? If so then you can do a DLookup in AfterUpdate Event on Code field:
Me.Description = DLookup("[Description]", "tblCodes", "Code = " & Me.Code)
No, I have over 400 codes, but I don't want that field to be a combo box. The are manually entered, we know the codes so its faster. I tried the DLookup you gave me above, but I got an error saying it could not find the tblCodes, so I removed the tbl part and it works, but it will only populate the description for the first record only.
Use a lookup query as the source for your form. I don't normally recommend these but if you are determined not to use a combo box that seems the likeliest way.
The lookup query would require you to have a code table where the code you're entering is the PRIMARY KEY of the code table (it must be defined as the primary key in the table design).
so for instance if you had the tables
The lookup query would beCode:tblErrCodes E_ID E_Desc 5710 GOJ tblErrors Err_ID E_ID Err_Qty ----> other error related fields
If you type 5710 in the E_ID field the description will be filled in automatically.Code:SELECT tblErrors.Err_ID, tblErrors.E_ID, tblErrors.Err_Qty, tblErrCodes.E_Desc FROM tblErrCodes RIGHT JOIN tblErrors ON tblErrCodes.E_ID = tblErrors.E_ID;
Then just adapt this for your data entry screen.
put a breakpoint on line with "Me.Description = DLookup("[Description]", "Codes", "Code = " & Me.Code)", when code is stopped, mouse over Me.Code(or whatever you text box name is) to see what value it has. It should be the code you put in the text box. Hit F8 to step though that 1 code line. Look at me.Description and see what it gives you.
I assume each Code value in that table is unique right?