Trying to populate form text boxes from a query (1 Viewer)

ritco

Registered User.
Local time
Today, 15:14
Joined
Apr 20, 2012
Messages
34
Can someone tell me what’s wrong with this code? I have a NotInList event that displays the Add New Record button and calls the below function. This function (PopulateItemTxtBoxes) is supposed to run a query to collect all the item information needed from a set of tables, populate/store that item info in text boxes on the form so that when the user clicks the add new record button, the item and all it’s info will be added to the table.
Private Function PopulateItemTxtBoxes()

Dim db As Database
Dim rsTable As Recordset
Dim qdfPara1 As QueryDef
Dim strSearchItem As String

Set db = CurrentDb

Set qdfPara1 = db.QueryDefs("QryGetItemInfo")

strSearchItem = Forms![frmInvValItemMaint]![cboItem]

qdfPara1![Forms!frmInvValItemMaint!cboItem] = strSearchItem

Set rsTable = qdfPara1.OpenRecordset()

‘This is where it errors. It doesn’t seem to be running the query and picking up the item information
Me.txtDescription.Value = rsTable![Description]
Me.txtStkUom.Value = rsTable![StockUom]
Me.txtProdClass.Value = rsTable![ProductClass]
Me.txtPartCat.Value = rsTable![PartCategory]
Me.txtDeadFlg.Value = rsTable![DeadFlag]
Me.txtSupercession.Value = rsTable![SupercessionDate]
Me.txtGrnShtCd.Value = rsTable![grnshtcode]
Me.txtLongDesc.Value = rsTable![LongDesc]
Me.txtInvSortCd.Value = rsTable![INVSORTCODE]
Me.txtInvSortCdDesc.Value = rsTable![InvSortCodeDesc]
Me.txtProfCtr.Value = rsTable![PROFITCENTER]
Me.txtProfCtrDesc.Value = rsTable![ProfitCDes]
'Me.txtLastCostChng.Value = rsTable![LastCostChgDate]
Me.txtPostDate.Value = Date
rsTable.Close
End Function
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 15:14
Joined
Aug 30, 2003
Messages
36,124
Offhand that looks okay, though I do this:

qdfStatement![Forms!frmMainMenu!txtDate] = Forms![frmMainMenu]![txtDate]

You might test for EOF, since the recordset might be empty. Have you tabbed off the combo to make sure the selection is made?
 

ritco

Registered User.
Local time
Today, 15:14
Joined
Apr 20, 2012
Messages
34
Problem solved! :)
Your suggestion to test for EOF made me take another look at my query. I had verified that the item existed so I didn't think about an empty dataset, but when I checked my query, the item was not getting picked up because I needed a "Left Join."


Thanks for your help!!!
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 15:14
Joined
Aug 30, 2003
Messages
36,124
No problemo!
 

Users who are viewing this thread

Top Bottom