Help with prefilling a form

S

springtime

I have a combo box that looks up names in a query and pre-fills that
information on the form if the name is found. If the name is not in the
list, then a data entry form opens up to add a new record then returns to the
form that called it. I use the following two commands to add the record.
(DoCmd.OpenForm "MyForm", acNormal, DoCmd.GoToRecord , , acNewRec) I can’t
get the newly added name to show up in the combo box list after returning to
the original form to pre-fill information. I have tried requery, but can’t
get it to work.
 
P

Piet Linden

I have a combo box that looks up names in a query and pre-fills that
information on the form if the name is found.  If the name is not in the
list, then a data entry form opens up to add a new record then returns tothe
form that called it.  I use the following two commands to add the record.  
(DoCmd.OpenForm "MyForm", acNormal, DoCmd.GoToRecord , , acNewRec) I can’t
get the newly added name to show up in the combo box list after returningto
the original form to pre-fill information.  I have tried requery, but can’t
get it to work.

Requery the combobox

Me.cboMyCombo.Requery
 
G

Gina Whipp

Springtime,

I don't know where you trying to use requery so I can't say why it's not
working but when I do this I put this on the On-Close of the data entry
form...
Forms![YourMainForm]![TheComboBoxOnTheMainFormYouWishToReuqery].Requery

However, if you use that form for anything else you might want to add

On Error Resume Next
Forms![YourMainForm]![TheComboBoxOnTheMainFormYouWishToReuqery].Requery

This way if the form is not open it should skip past the error that will
incur. I use the the IsLoaded which you can use also but you need the
IsLoaded added to a module....

If IsLoaded("YourMainForm") Then

Forms![YourMainForm]![TheComboBoxOnTheMainFormYouWishToReuqery].Requery
End If

Add IsLoaded to a module and name it modUtilities

'Beginning Code
Function IsLoaded(ByVal strFormName As String) As Boolean
' Returns True if the specified form is open in Form view or Datasheet
view.

Const conObjStateClosed = 0
Const conDesignView = 0

If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <>
conObjStateClosed Then
If Forms(strFormName).CurrentView <> conDesignView Then
IsLoaded = True
End If
End If

End Function
'End Code

--
Gina Whipp

"I feel I have been denied critical, need to know, information!" - Tremors
II

http://www.regina-whipp.com/index_files/TipList.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top