Add data from a Form for another Form

R

RIDEMNSLIDEM

I have a form with a combo box (ie. permit numbers) if no number is listed in
that box, then click the user clicks on a button to open a data entry form
to enter "permit number, name, address". This all works fine.
My problem occurs when I close the "add" form, my original form is not
updated with the new data that was just entered. Any suggestions would be
greatful.
 
D

Damon Heron

Right after the command to open the form as dialog, put
me.YourCombobox.requery

Damon
 
R

RIDEMNSLIDEM

Thanks for responding Damon,
I am pretty much a rookie at this. So please help me a little more, do I
enter this with the "On Click" verbage?

Damon said:
Right after the command to open the form as dialog, put
me.YourCombobox.requery

Damon
I have a form with a combo box (ie. permit numbers) if no number is listed
in
[quoted text clipped - 4 lines]
updated with the new data that was just entered. Any suggestions would be
greatful.
 
J

Jeff Boyce

Another approach might be to use the NotInList event to help do what you are
doing. Check Access HELP on that...

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
R

RIDEMNSLIDEM

Hi Jeff
I did check help and this seems to be what I need, but could you give me an
example of code to write? If I do the Event Procedure on the NotInList, is
that where I enter the Me.cboPermitOperatorID.Requery statement?

Jeff said:
Another approach might be to use the NotInList event to help do what you are
doing. Check Access HELP on that...

Regards

Jeff Boyce
Microsoft Office/Access MVP
I have a form with a combo box (ie. permit numbers) if no number is listed
in
[quoted text clipped - 4 lines]
updated with the new data that was just entered. Any suggestions would be
greatful.
 
J

Jeff Boyce

If you'll check Access HELP, it provides a complete example of how to set up
the NotInList event, code and all...

Regards

Jeff Boyce
Microsoft Office/Access MVP


RIDEMNSLIDEM said:
Hi Jeff
I did check help and this seems to be what I need, but could you give me
an
example of code to write? If I do the Event Procedure on the NotInList,
is
that where I enter the Me.cboPermitOperatorID.Requery statement?

Jeff said:
Another approach might be to use the NotInList event to help do what you
are
doing. Check Access HELP on that...

Regards

Jeff Boyce
Microsoft Office/Access MVP
I have a form with a combo box (ie. permit numbers) if no number is
listed
in
[quoted text clipped - 4 lines]
updated with the new data that was just entered. Any suggestions would
be
greatful.
 
D

Damon Heron

Yes. You said you have a command button. In the click event, you would have
something like this:

DoCmd.OpenForm "YourFormName", acNormal, , , , acDialog
Me.YourCombobox.Requery

Alternatively, with a bit more coding, you could use the Not in List event
that Jeff mentioned. There are a few problems associated with doing it this
way though, but here is some code I have used if you want to try it:

'Set the combobox property "Limit to List" to yes. Set
'the Allow Value lists edit to no.
'Make sure you have a reference to DAO.

'Add this code, changing my fields and tables to yours:

Private Sub Combo4_NotInList(NewData As String, Response As Integer)
Dim Db As DAO.Database
Dim Rs As DAO.Recordset
Dim Msg As String
Dim NewID As String

On Error GoTo Err_Combo4_NotInList

' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub

' Confirm that the user wants to add the new customer.
Msg = "'" & NewData & "' is not in the list." & vbCr & vbCr
Msg = Msg & "Do you want to add it?"
If MsgBox(Msg, vbQuestion + vbYesNo) = vbNo Then
' If the user chose not to add a record, set the Response
' argument to suppress an error message and undo changes.
Response = acDataErrContinue
' Display a customized message.
MsgBox "Please try again."
Else
' If the user chose to add a new record, open a recordset
' using the table.
Set Db = CurrentDb
Set Rs = Db.OpenRecordset("tblEmp", dbOpenDynaset)
' Ask the user to input a new Emp ID.
Msg = "Please enter a unique 3-character" & vbCr & "Emp ID."
NewID = InputBox(Msg)
Rs.FindFirst BuildCriteria("EmpID", dbText, NewID)
' If the NewID already exists, ask for another new unique
' ID
Do Until Rs.NoMatch
NewID = InputBox("Emp ID " & NewID & " already exists." & _
vbCr & vbCr & Msg, NewID & " Already Exists")
Rs.FindFirst BuildCriteria("EmpID", dbText, NewID)
Loop

' Create a new record.
Rs.AddNew
' Assign the NewID to the EmpID field.
Rs![EmpID] = NewID
' Assign the NewData argument to the EmployeeName field.
Rs![EmpNm] = NewData
' Save the record.
Rs.Update

' Set Response argument to indicate that new data is being added.
Response = acDataErrAdded

End If

Exit_Combo4_NotInList:
Exit Sub
Err_Combo4_NotInList:
' An unexpected error occurred, display the normal error message.
MsgBox Err.Description
' Set the Response argument to suppress an error message and undo
' changes.
Response = acDataErrContinue
End Sub

Damon


RIDEMNSLIDEM said:
Thanks for responding Damon,
I am pretty much a rookie at this. So please help me a little more, do I
enter this with the "On Click" verbage?

Damon said:
Right after the command to open the form as dialog, put
me.YourCombobox.requery

Damon
I have a form with a combo box (ie. permit numbers) if no number is
listed
in
[quoted text clipped - 4 lines]
updated with the new data that was just entered. Any suggestions would
be
greatful.
 
R

RIDEMNSLIDEM via AccessMonster.com

Thank you very much for all your help.

Tracy

Damon said:
Yes. You said you have a command button. In the click event, you would have
something like this:

DoCmd.OpenForm "YourFormName", acNormal, , , , acDialog
Me.YourCombobox.Requery

Alternatively, with a bit more coding, you could use the Not in List event
that Jeff mentioned. There are a few problems associated with doing it this
way though, but here is some code I have used if you want to try it:

'Set the combobox property "Limit to List" to yes. Set
'the Allow Value lists edit to no.
'Make sure you have a reference to DAO.

'Add this code, changing my fields and tables to yours:

Private Sub Combo4_NotInList(NewData As String, Response As Integer)
Dim Db As DAO.Database
Dim Rs As DAO.Recordset
Dim Msg As String
Dim NewID As String

On Error GoTo Err_Combo4_NotInList

' Exit this subroutine if the combo box was cleared.
If NewData = "" Then Exit Sub

' Confirm that the user wants to add the new customer.
Msg = "'" & NewData & "' is not in the list." & vbCr & vbCr
Msg = Msg & "Do you want to add it?"
If MsgBox(Msg, vbQuestion + vbYesNo) = vbNo Then
' If the user chose not to add a record, set the Response
' argument to suppress an error message and undo changes.
Response = acDataErrContinue
' Display a customized message.
MsgBox "Please try again."
Else
' If the user chose to add a new record, open a recordset
' using the table.
Set Db = CurrentDb
Set Rs = Db.OpenRecordset("tblEmp", dbOpenDynaset)
' Ask the user to input a new Emp ID.
Msg = "Please enter a unique 3-character" & vbCr & "Emp ID."
NewID = InputBox(Msg)
Rs.FindFirst BuildCriteria("EmpID", dbText, NewID)
' If the NewID already exists, ask for another new unique
' ID
Do Until Rs.NoMatch
NewID = InputBox("Emp ID " & NewID & " already exists." & _
vbCr & vbCr & Msg, NewID & " Already Exists")
Rs.FindFirst BuildCriteria("EmpID", dbText, NewID)
Loop

' Create a new record.
Rs.AddNew
' Assign the NewID to the EmpID field.
Rs![EmpID] = NewID
' Assign the NewData argument to the EmployeeName field.
Rs![EmpNm] = NewData
' Save the record.
Rs.Update

' Set Response argument to indicate that new data is being added.
Response = acDataErrAdded

End If

Exit_Combo4_NotInList:
Exit Sub
Err_Combo4_NotInList:
' An unexpected error occurred, display the normal error message.
MsgBox Err.Description
' Set the Response argument to suppress an error message and undo
' changes.
Response = acDataErrContinue
End Sub

Damon
Thanks for responding Damon,
I am pretty much a rookie at this. So please help me a little more, do I
[quoted text clipped - 12 lines]
 
R

RIDEMNSLIDEM via AccessMonster.com

Thank you very much for all your help.

Tracy

Jeff said:
Another approach might be to use the NotInList event to help do what you are
doing. Check Access HELP on that...

Regards

Jeff Boyce
Microsoft Office/Access MVP
I have a form with a combo box (ie. permit numbers) if no number is listed
in
[quoted text clipped - 4 lines]
updated with the new data that was just entered. Any suggestions would be
greatful.
 

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