open form and use value from combobox to populate table

megatronixs

Registered User.
Local time
Today, 03:08
Joined
Aug 17, 2012
Messages
719
Hi all,

I'm trying to capture a call outcome to our database.
When the user calls the client, she/he needs to click on a button to pop up a form where she/he can select one of the 3 outcome of the phone call (like made contact, made no contact, call postponed).
once the user selects an option from the form, this should put the value selected on the table and then close.
I have so far the below code:
Code:
Private Sub btn_step1_contact_Click()
Dim stDocName As String
Dim Combo0 As String
    stDocName = "frm_phone_contact_outcome"
    DoCmd.OpenForm stDocName, , , ""
 
DoCmd.GoToControl ("frm_step1_contact")
DoCmd.GoToRecord , , acNewRec
Me!frm_step1_contact![date_time_contact] = Now
Me!frm_step1_contact![analyst_contact] = GetUserFullName
End Sub

so far I can only have the form pop up, but no clue how to capture the value and add it to the table in the field "phone_contact_outcome"
the combobox in the form "frm_phone_contact_outcome" is called "Combo0" (I will still rename the combobox to something more usefull)

Greetings.
 
Set the value when the popup form close, because when the popup form is closed you can't get access to the option selected in the popup form.
 
Hi,
I created the on click action, but on the small popup fomr. when the user clicks on one the combobox to select one, it will remember the choice and a debug.print will show the selected text, but I can get it to be passed on the table.
Actually this table is a separate table that is used in a subform in datasheet view. It is conencted via the record id to the main table. I can put the other data into it (date time and user name), but can't pass the value of the combobox to the table.
I guess there is something I mess and can't figure out.

Greetings.
 
I tried to have it on the form that pops up with the choice for phone contact outcome. Still no luck (it does not find the form with the controls)
this what I got so far:
Code:
Option Compare Database
Private Sub Combo0_Click()
Dim stDocName As String
Dim Combo0 As String
    stDocName = "frm_step1_contact"
    DoCmd.GoToRecord , , acNewRec
Me!frm_step1_contact.[date_time_contact] = Now
Me!frm_step1_contact![analyst_contact] = GetUserFullName
Me!frm_step1_contact![phone_contact_outcome].Combo0.Value
End Sub

Greetings.
 
Post your database with some sample data, zip it.
 
You are referring to the wrong form object. The syntax is Forms!YourFormName!ControlName note the use of the ! instead of the. I think you need to use;
Code:
Forms!frm_step1_contact![date_time_contact] = Now
Forms!frm_step1_contact![analyst_contact] = GetUserFullName
Forms!frm_step1_contact![phone_contact_outcome] = Me.Combo0

Assuming those are the control names, and not the field names. A small recommendation - rename your text box controls to txtFieldName you then know you are referring to the control and not the field.

Note that I removed the .Value from your reference to the combo as well. don't use .Value it is the default property and can cause error particularly with combo controls.
 
Hi all,

I made it partially work like this:
the button on the main form opens a stand alone form that has the combobox in it. When I select one option, the click event triggers the below code:
Code:
Private Sub Combo0_Click()
Dim stDocName As String
Dim Combo0 As String
   
        stDocName = "frm_step1_contact"
    DoCmd.GoToRecord , , acNewRec
    Forms!frm_Edit_Reviews!frm_step1_contact.Form![date_time_contact] = Now
    Forms!frm_Edit_Reviews!frm_step1_contact.Form![contact_outcome] = Me.Combo0
    Forms!frm_Edit_Reviews!frm_step1_contact.Form![analyst_contact] = GetUserFullName
End Sub
I still need to get the
Code:
        stDocName = "frm_step1_contact"
    DoCmd.GoToRecord , , acNewRec
to really add it to the form. Now it only will popup on the table.
I still need it to close the form after the option was selected from the combobox.

Greetings
 
I would add a close and cancel cmdButton to your popup, pressing the close button does all your update code, pressing cancel simply closes it without doing the update if they pressed it by mistake.

Something like ;
Code:
Private Sub cmdClose_Click()

    Forms!frm_Edit_Reviews.Recordset.AddNew
    Forms!frm_Edit_Reviews!frm_step1_contact.Form![date_time_contact] = Now
    Forms!frm_Edit_Reviews!frm_step1_contact.Form![contact_outcome] = Me.Combo0
    Forms!frm_Edit_Reviews!frm_step1_contact.Form![analyst_contact] = GetUserFullName

    DoCmd.Close "frm_phone_contact_outcome"

End Sub

'''''''''''''''''''''''''''
Private Sub cmdCancel_Click()

    DoCmd.Close "frm_phone_contact_outcome"

End Sub
 
Hi all,

At the end I just put the combobox straight in the main form.
The user selects the option and the data is placed in the table and vissible in the subform. Then I just empty the combobox:
Code:
Private Sub Combo786_Click()
Dim stDocName As String
DoCmd.GoToControl ("frm_step1_contact")
    DoCmd.GoToRecord , , acNewRec
    Forms!frm_Edit_Reviews!frm_step1_contact.Form![date_time_contact] = Now
        Forms!frm_Edit_Reviews!frm_step1_contact.Form![contact_outcome] = Me.Combo786
            Forms!frm_Edit_Reviews!frm_step1_contact.Form![analyst_contact] = GetUserFullName
    
    Me.Combo786 = ""
    
End Sub
Mybe it is not the most elegant way, but at least they don't have to get the extra pop-up form.

Greetings
 
I personally would use the after update event rather than click, it means things only happen if the value is changed.
 

Users who are viewing this thread

Back
Top Bottom