Use a different default value on a form..

  • Thread starter Darrell Childress
  • Start date
D

Darrell Childress

I have a form (frmJobStart) that I would like to open by clicking on 8
different buttons on another form. The frmJobStart contains a field
named WorkCenter. If I click on Button1, I would like to open
frmJobStart with the "WorkCenter" field defaulted to Weld. If I click on
Button2, I would like to open frmJobStart with the "WorkCenter" field
defaulted to Assy.
Is this possible? I assume I would need to put some code behind each of
the 8 buttons being used to open the form. Using Access 2003.
Thanks,
Darrell
 
F

fredg

I have a form (frmJobStart) that I would like to open by clicking on 8
different buttons on another form. The frmJobStart contains a field
named WorkCenter. If I click on Button1, I would like to open
frmJobStart with the "WorkCenter" field defaulted to Weld. If I click on
Button2, I would like to open frmJobStart with the "WorkCenter" field
defaulted to Assy.
Is this possible? I assume I would need to put some code behind each of
the 8 buttons being used to open the form. Using Access 2003.
Thanks,
Darrell

Code Command Button1:
Docmd.OpenForm "frmJobStart", , , , , , "Weld"

Code Command Button2:
Docmd.OpenForm "frmJobStart", , , , , , "Assy"

etc. for each of the other buttons.

Code the frmJobStart Load event:

If Not IsNull(Me.OpenArgs) Then
Me.[Work Center].DefaultValue = """" & Me.OpenArgs & """"
End If

Note: In my opinion you are using a cumbersome method (8 different
command buttons) to open the one form with the different default
values.

Why not use an Option Group, with the 8 choices ("Weld", "Assy",
"etc..".
Code the Option Group AfterUpdate event:

DoCmd.OpenForm "frmJobStart", , , , , ,
Choose([OptionGroupName],"Weld","Assy","etc..")

No need of a command button, or if you wish, use just one command
button, using the same code.
 
D

Darrell Childress

Thanks for the response. I like your method better and started to ask if
anyone had a suggestion of a better method to do this. I had not thought
of using an option group, but I'm going to try to set it up using that
method. Is there possibly a way that I could make the button to open the
new form either invisible or inoperable unless an option is chosen in
the option group? This is going to be a form where employees log into a
job and I don't want them to be able to start the sequence unless
they've chosen the department they're working in.
I have a form (frmJobStart) that I would like to open by clicking on 8
different buttons on another form. The frmJobStart contains a field
named WorkCenter. If I click on Button1, I would like to open
frmJobStart with the "WorkCenter" field defaulted to Weld. If I click on
Button2, I would like to open frmJobStart with the "WorkCenter" field
defaulted to Assy.
Is this possible? I assume I would need to put some code behind each of
the 8 buttons being used to open the form. Using Access 2003.
Thanks,
Darrell

Code Command Button1:
Docmd.OpenForm "frmJobStart", , , , , , "Weld"

Code Command Button2:
Docmd.OpenForm "frmJobStart", , , , , , "Assy"

etc. for each of the other buttons.

Code the frmJobStart Load event:

If Not IsNull(Me.OpenArgs) Then
Me.[Work Center].DefaultValue = """" & Me.OpenArgs & """"
End If

Note: In my opinion you are using a cumbersome method (8 different
command buttons) to open the one form with the different default
values.

Why not use an Option Group, with the 8 choices ("Weld", "Assy",
"etc..".
Code the Option Group AfterUpdate event:

DoCmd.OpenForm "frmJobStart", , , , , ,
Choose([OptionGroupName],"Weld","Assy","etc..")

No need of a command button, or if you wish, use just one command
button, using the same code.
 
F

fredg

Thanks for the response. I like your method better and started to ask if
anyone had a suggestion of a better method to do this. I had not thought
of using an option group, but I'm going to try to set it up using that
method. Is there possibly a way that I could make the button to open the
new form either invisible or inoperable unless an option is chosen in
the option group? This is going to be a form where employees log into a
job and I don't want them to be able to start the sequence unless
they've chosen the department they're working in.
I have a form (frmJobStart) that I would like to open by clicking on 8
different buttons on another form. The frmJobStart contains a field
named WorkCenter. If I click on Button1, I would like to open
frmJobStart with the "WorkCenter" field defaulted to Weld. If I click on
Button2, I would like to open frmJobStart with the "WorkCenter" field
defaulted to Assy.
Is this possible? I assume I would need to put some code behind each of
the 8 buttons being used to open the form. Using Access 2003.
Thanks,
Darrell

Code Command Button1:
Docmd.OpenForm "frmJobStart", , , , , , "Weld"

Code Command Button2:
Docmd.OpenForm "frmJobStart", , , , , , "Assy"

etc. for each of the other buttons.

Code the frmJobStart Load event:

If Not IsNull(Me.OpenArgs) Then
Me.[Work Center].DefaultValue = """" & Me.OpenArgs & """"
End If

Note: In my opinion you are using a cumbersome method (8 different
command buttons) to open the one form with the different default
values.

Why not use an Option Group, with the 8 choices ("Weld", "Assy",
"etc..".
Code the Option Group AfterUpdate event:

DoCmd.OpenForm "frmJobStart", , , , , ,
Choose([OptionGroupName],"Weld","Assy","etc..")

No need of a command button, or if you wish, use just one command
button, using the same code.

You really should try to help yourself before asking here.
Read VBA help on the OpenForm method.
It will tell you what arguments you can use.
Also, when actually writing the code, the VBA Intellisense feature
will offer you the constant values for each argument as you type.

You can set the 5th argument to open the form hidden:
DoCmd.OpenForm "frmJobStart", , , , , acHidden ,
Choose([OptionGroupName],"Weld","Assy","etc..")

Or you can set the 4tth argument to acFormReadOnly to prevent editing
the data in the form:

DoCmd.OpenForm "frmJobStart", , , , acFormReadOnly , ,
Choose([OptionGroupName],"Weld","Assy","etc..")
 

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