Form to add and update data

  • Thread starter Thread starter omsoft
  • Start date Start date
O

omsoft

I have a form which I use to add and update data.
The code path for add and update is different.
For add, I bring up the form with the following code on a button click event.

stDocName = "frm_sessions"
DoCmd.OpenForm stDocName, acNormal, , , acFormAdd
DoCmd.GoToRecord , , acNewRec

For update I first have a dropdown to determine which record to bring up to
modify. The query that runs to get the record is working. But the form is not
getting populated. I use the following to bring up the form.

stDocName = "frm_SessModify"
strQryName = "qry_ModSession"
DoCmd.OpenForm stDocName, , strQryName, , acFormEdit

The form does not come up but is not populated with data.

There are no compile problems. I have checked that. Is there anything in the
form properties where I should check to make sure the data is populated?

Thanks,
 
Hi omsoft,

the problem is with using strQryName = "qry_ModSession"

You need instead to use a where clause.
Something like this

Dim strWhere as String
strWhere = "[SessionID] = " & Me.DropdownName
stDocName = "frm_sessions"
DoCmd.OpenForm stDocName, , , strWhere , acFormEdit


Note: replace SessionID with the correct field for your form and
DropdownName with the name of the combo.
If the ID field is text, you will need the extra quotes that we always use
for text data type.


Jeanette Cunningham MS Access MVP -- Melbourne Victoria Australia
 
Back
Top