Passing Values from One Form to Another Including a Combo Box

M

Maurita

Hi, hope someone can help with passing two values from one form to
another by way of a command button. I have spent a week on various
code taken from this site, but still no luck. Please ... someone help!!

The form I am passing values from is called PATIENT HISTORY-Form. On
this form, I need to pass a date from a field called DateSFESigned and
I also need to pass information collected from a Combo box, Combo91.

The command button is called Command119.

The form that the values are being passed to is called Personal Habits-
Form.

Thank you in advance for any help on this matter.

Maurita Searcy
 
K

Ken Snell \(MVP\)

There are various ways to do this; as for which may be best for you to use,
that depends upon what the second form wants to do with the values.

First thing I'd try is using OpenArgs argument in the DoCmd.OpenForm action.
Concatenate the two values into a single string (separate them with some
unique delimiter, such as the pipe | character), and the parse the string
back into individual values in the second form's Load event procedure.

Or you could have the second form read the values directly from the first
form, if the first form is still open; again, I'd use the second form's Load
event procedure.

Or you could have the first form write the values into textboxes on the
second form.

And there are other ways. You'll need to give us more information about what
you're wanting to do in this situation.
 
A

Al Campagna

Maurita,
Assuming your going from Main form to Main form, and both forms are open.
(You did not indicate what fields you were going to on the second form)
Private Sub Command119_Click
Forms![Personal Habits-Form]![SomeFieldName] = Forms![Patient
History-Form]![DateSFESigned]
Forms![Personal Habits-Form]![SomeFieldName] = Forms![Patient
History-Form]![Combo91]
Refresh 'optional
End Sub

Suggestion: You should avoid spaces in your object names (frmPersonalHabits instead of
[Personal Habits-Form])
and use names that are meaningful (cboSelectItem instead of Combo91) Object names with no
spaces don't require bracketing, and meaningful names will help you read and understand
your code.

--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVP
http://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."
 
M

Maurita

Maurita,
   Assuming your going from Main form to Main form, and both forms are open.
   (You did not indicate what fields you were going to on the second form)
   Private Sub Command119_Click
        Forms![Personal Habits-Form]![SomeFieldName] = Forms![Patient
History-Form]![DateSFESigned]
        Forms![Personal Habits-Form]![SomeFieldName] = Forms![Patient
History-Form]![Combo91]
        Refresh   'optional
   End Sub

   Suggestion: You should avoid spaces in your object names (frmPersonalHabits instead of
[Personal Habits-Form])
and use names that are meaningful (cboSelectItem instead of Combo91)  Object names with no
spaces don't require bracketing, and meaningful names will help you read and understand
your code.

--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVPhttp://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."




Hi, hope someone can help with passing two values from one form to
another by way of a command button.  I have spent a week on various
code taken from this site, but still no luck.  Please ... someone help!!
The form I am passing values from is called PATIENT HISTORY-Form.  On
this form, I need to pass a date from a field called DateSFESigned and
I also need to pass information collected from a Combo box, Combo91.
The command button is called Command119.
The form that the values are being passed to is called Personal Habits-
Form.
Thank you in advance for any help on this matter.
MauritaSearcy- Hide quoted text -

- Show quoted text -

Thank you so much for your help. I will work on your suggestions and
let you know how it works. Again, thanks.
 
M

Maurita

Maurita,
? ?Assuming your going from Main form to Main form, and both forms are open.
? ?(You did not indicate what fields you were going to on the second form)
? ?Private Sub Command119_Click
? ? ? ? Forms![Personal Habits-Form]![SomeFieldName] = Forms![Patient
History-Form]![DateSFESigned]
? ? ? ? Forms![Personal Habits-Form]![SomeFieldName] = Forms![Patient
History-Form]![Combo91]
? ? ? ? Refresh ? 'optional
? ?End Sub
? ?Suggestion: You should avoid spaces in your object names (frmPersonalHabits instead of
[Personal Habits-Form])
and use names that are meaningful (cboSelectItem instead of Combo91) ?Object names with no
spaces don't require bracketing, and meaningful names will help you read and understand
your code.
"Find a job that you love, and you'll never work a day in your life."
- Show quoted text -

Thank you so much for your help.  I will work on your suggestions and
let you know how it works.  Again, thanks.- Hide quoted text -

- Show quoted text -

Thank you again for your help but I have a problem. For some reason,
I keep getting an error "Switchboard can't find the form", but the
form is in the database and I checked to be sure it is workable, which
it is. What do you suggest. My code is as follows:

Private Sub Command114_Click()

Forms![frmPersonalHabits]![PHDate] = Forms![frmPatientHistory]!
[DateSFESigned]
Forms![frmPersonalHabits]![Combo91] = Forms![frmPatientHistory]!
[Combo91]
Refresh
End Sub

Thank you.

Maurita Searcy
 
A

Al Campagna

Maurita,
? ?Assuming your going from Main form to Main form, and both forms are open.
? ?(You did not indicate what fields you were going to on the second form)
? ?Private Sub Command119_Click
? ? ? ? Forms![Personal Habits-Form]![SomeFieldName] = Forms![Patient
History-Form]![DateSFESigned]
? ? ? ? Forms![Personal Habits-Form]![SomeFieldName] = Forms![Patient
History-Form]![Combo91]
? ? ? ? Refresh ? 'optional
? ?End Sub
? ?Suggestion: You should avoid spaces in your object names (frmPersonalHabits instead
of
[Personal Habits-Form])
and use names that are meaningful (cboSelectItem instead of Combo91) ?Object names
with no
spaces don't require bracketing, and meaningful names will help you read and
understand
your code.
"Find a job that you love, and you'll never work a day in your life."
- Show quoted text -

Thank you so much for your help. I will work on your suggestions and
let you know how it works. Again, thanks.- Hide quoted text -

- Show quoted text -

Thank you again for your help but I have a problem. For some reason,
I keep getting an error "Switchboard can't find the form", but the
form is in the database and I checked to be sure it is workable, which
it is. What do you suggest. My code is as follows:

Private Sub Command114_Click()

Forms![frmPersonalHabits]![PHDate] = Forms![frmPatientHistory]!
[DateSFESigned]
Forms![frmPersonalHabits]![Combo91] = Forms![frmPatientHistory]!
[Combo91]
Refresh
End Sub

Thank you.

Maurita Searcy
-------------------------------
Maurita,
From my first post...
Assuming your going from Main form to Main form, and both forms are open.
Both forms need to be open at the time this code runs, and you should be on
frmPatientHistory when it fires... and having just entered values in both controls.

If those forms aren't open, and your not on the specific record you want to copy the
values from, how would Access know what record, and what values in the History
recordset... to transfer to Habits?

--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVP
http://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."
 
M

Maurita

Maurita,
? ?Assuming your going from Main form to Main form, and both forms are open.
? ?(You did not indicate what fields you were going to on the second form)
? ?Private Sub Command119_Click
? ? ? ? Forms![Personal Habits-Form]![SomeFieldName] = Forms![Patient
History-Form]![DateSFESigned]
? ? ? ? Forms![Personal Habits-Form]![SomeFieldName] = Forms![Patient
History-Form]![Combo91]
? ? ? ? Refresh ? 'optional
? ?End Sub
? ?Suggestion: You should avoid spaces in your object names (frmPersonalHabits instead
of
[Personal Habits-Form])
and use names that are meaningful (cboSelectItem instead of Combo91) ?Object names
with no
spaces don't require bracketing, and meaningful names will help you read and
understand
your code.
--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVPhttp://home.comcast.net/~cccsolutions
"Find a job that you love, and you'll never work a day in your life."

Hi, hope someone can help with passing two values from one form to
another by way of a command button. ?I have spent a week on various
code taken from this site, but still no luck. ?Please ... someone help!!
The form I am passing values from is called PATIENT HISTORY-Form. ?On
this form, I need to pass a date from a field called DateSFESigned and
I also need to pass information collected from a Combo box, Combo91.
The command button is called Command119.
The form that the values are being passed to is called Personal Habits-
Form.
Thank you in advance for any help on this matter.
MauritaSearcy- Hide quoted text -
- Show quoted text -
Thank you so much for your help. I will work on your suggestions and
let you know how it works. Again, thanks.- Hide quoted text -
- Show quoted text -

Thank you again for your help but I have a problem.  For some reason,
I keep getting an error "Switchboard can't find the form", but the
form is in the database and I checked to be sure it is workable, which
it is.  What do you suggest.  My code is as follows:

Private Sub Command114_Click()

Forms![frmPersonalHabits]![PHDate] = Forms![frmPatientHistory]!
[DateSFESigned]
Forms![frmPersonalHabits]![Combo91] = Forms![frmPatientHistory]!
[Combo91]
Refresh
End Sub

Thank you.

MauritaSearcy
-------------------------------Maurita,
   From my first post...>Assuming your going from Main form to Main form, and both forms are open.

  Both forms need to be open at the time this code runs, and you shouldbe on
frmPatientHistory when it fires... and having just entered values in bothcontrols.

  If those forms aren't open, and your not on the specific record you want to copy the
values from, how would Access know what record, and what values in the History
recordset... to transfer to Habits?

--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVPhttp://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."- Hide quoted text -

- Show quoted text -

Al,

Thanks for your reply. The Main form is frmPatientHistory, which has
the command button that calls up frmPersonalHabits. I do want the
main form frmPatientHistory to remain open because as soon as
frmPersonalHabits is completed, the user will click on another command
button to return to the main form frmPatientHistory. I entered
information into the frmPatientHistory and clicked the command button
with the code written above, but I still have the same "Switchboard
Can't Find Form" error. If I click on the form outside the
switchboard, it opens fine. I am at a loss as to what is going on.

Thank you.

Maurita
 
A

Al Campagna

Maurita,
? ?Assuming your going from Main form to Main form, and both forms are open.
? ?(You did not indicate what fields you were going to on the second form)
? ?Private Sub Command119_Click
? ? ? ? Forms![Personal Habits-Form]![SomeFieldName] = Forms![Patient
History-Form]![DateSFESigned]
? ? ? ? Forms![Personal Habits-Form]![SomeFieldName] = Forms![Patient
History-Form]![Combo91]
? ? ? ? Refresh ? 'optional
? ?End Sub
? ?Suggestion: You should avoid spaces in your object names (frmPersonalHabits
instead
of
[Personal Habits-Form])
and use names that are meaningful (cboSelectItem instead of Combo91) ?Object names
with no
spaces don't require bracketing, and meaningful names will help you read and
understand
your code.
--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVPhttp://home.comcast.net/~cccsolutions
"Find a job that you love, and you'll never work a day in your life."

Hi, hope someone can help with passing two values from one form to
another by way of a command button. ?I have spent a week on various
code taken from this site, but still no luck. ?Please ... someone help!!
The form I am passing values from is called PATIENT HISTORY-Form. ?On
this form, I need to pass a date from a field called DateSFESigned and
I also need to pass information collected from a Combo box, Combo91.
The command button is called Command119.
The form that the values are being passed to is called Personal Habits-
Form.
Thank you in advance for any help on this matter.
MauritaSearcy- Hide quoted text -
- Show quoted text -
Thank you so much for your help. I will work on your suggestions and
let you know how it works. Again, thanks.- Hide quoted text -
- Show quoted text -

Thank you again for your help but I have a problem. For some reason,
I keep getting an error "Switchboard can't find the form", but the
form is in the database and I checked to be sure it is workable, which
it is. What do you suggest. My code is as follows:

Private Sub Command114_Click()

Forms![frmPersonalHabits]![PHDate] = Forms![frmPatientHistory]!
[DateSFESigned]
Forms![frmPersonalHabits]![Combo91] = Forms![frmPatientHistory]!
[Combo91]
Refresh
End Sub

Thank you.

MauritaSearcy
-------------------------------Maurita,
From my first post...>Assuming your going from Main form to Main form, and both forms
are open.

Both forms need to be open at the time this code runs, and you should be on
frmPatientHistory when it fires... and having just entered values in both controls.

If those forms aren't open, and your not on the specific record you want to copy the
values from, how would Access know what record, and what values in the History
recordset... to transfer to Habits?

--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVPhttp://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."- Hide quoted
text -

- Show quoted text -

Al,

Thanks for your reply. The Main form is frmPatientHistory, which has
the command button that calls up frmPersonalHabits. I do want the
main form frmPatientHistory to remain open because as soon as
frmPersonalHabits is completed, the user will click on another command
button to return to the main form frmPatientHistory. I entered
information into the frmPatientHistory and clicked the command button
with the code written above, but I still have the same "Switchboard
Can't Find Form" error. If I click on the form outside the
switchboard, it opens fine. I am at a loss as to what is going on.

Thank you.

Maurita

Sorry, I never use Switchboards, so I don't think I can help you there. To me, they are
more trouble than they are worth.
I build a form and place my own buttons and code behind them.
I'm a bit "confoosed"... as to why a button on a form involves a switchboard at all. My
code is meant to be placed in the form's VBA module.
Try creating a new button on the form, and place my code behind the On_Click event.

Make sure you use your own object names in your code, not my example names, and... if you
use spaces in your names, make sure ALL references to that object are bracketed.
Otherwise, you'll have to go into your switchboard and try to find out why it can't find
your code objects.

--
hth
Al Campagna . Candia Computer Consulting . Candia, NH USA
Microsoft Access MVP
http://home.comcast.net/~cccsolutions

"Find a job that you love, and you'll never work a day in your life."
 

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