Setting default values on Form Open

G

Guest

[Access 03]

I have a form with two combo boxes (cboCompany, cboContact) that are
prefilled based on selections from a superior form. There are two text boxes
corresponding to these combo boxes for the user to enter alternate names for
both Company and Contact. I would like these to default to the values in the
combo boxes.

On my Form Open property I have the following code. My error message is
either "You can't assign a value to this object" or "The object or property
doesn't support this method." I have varied the code to try .Value,
..DefaultValue as well as other more grasping (and less logical) options.
Seems like a fairly simple thing - can anyone help?

The form name is frmExhibitor
cboCompany has data fields of CompanyID, CompanyName, ContactID and
ContactFullName

Me.txtAltCompanyName.Value = Forms![frmExhibitors]!cboCompany.[Column(1)]
Me.txtAltContactFullName.Value = Forms![frmExhibitors]!cboCompany.[Column(3)]

(The prefill functions for cboCompany and cboContact work just fine - it's
the alternate information that I can't get to autocomplete.)

Any help is appreciated!
 
A

Allen Browne

You really don't want to change the values every time the form is opened,
thus overwriting any previous entries that may have been made in whichever
record happens to come up in the form.

Your subject suggests setting the Default Value, so perhaps something like
this:

Private Sub Form_Open(Cancel As Integer)
If CurrentProject.AllForms("frmExhibitors").IsLoaded Then
With Forms("frmExhibitors")!cboCompany
If Not IsNull(.Value) Then
If .Column(1) <> vbnullstring then
Me.txtAltCompanyName.DefaultValue = """" & .Column(1) &
""""
End If
If .Column(3) <> vbnullstring then
Me.txtAltContactFullName.DefaultValue = """" &
..Column(3) & """"
End If
End If
End With
End If
End Sub
 
G

Guest

Allen,

Thank you very much. This works perfectly (of course!!). :)

BTW - I've noticed that when in the newsgroups and double-clicking on a
post, I used to be able to scroll through messages and then click on YES for
a post answering my question or being helpful. Now when the new window
appears, the vertical scrollbar is missing and I am not able to review
subsequent posts NOR am I able to get to your post and mark your response
accordingly. Has the open post webpage design changed?

Anyway, thanks for your help as always.

Allen Browne said:
You really don't want to change the values every time the form is opened,
thus overwriting any previous entries that may have been made in whichever
record happens to come up in the form.

Your subject suggests setting the Default Value, so perhaps something like
this:

Private Sub Form_Open(Cancel As Integer)
If CurrentProject.AllForms("frmExhibitors").IsLoaded Then
With Forms("frmExhibitors")!cboCompany
If Not IsNull(.Value) Then
If .Column(1) <> vbnullstring then
Me.txtAltCompanyName.DefaultValue = """" & .Column(1) &
""""
End If
If .Column(3) <> vbnullstring then
Me.txtAltContactFullName.DefaultValue = """" &
..Column(3) & """"
End If
End If
End With
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Pendragon said:
[Access 03]

I have a form with two combo boxes (cboCompany, cboContact) that are
prefilled based on selections from a superior form. There are two text
boxes
corresponding to these combo boxes for the user to enter alternate names
for
both Company and Contact. I would like these to default to the values in
the
combo boxes.

On my Form Open property I have the following code. My error message is
either "You can't assign a value to this object" or "The object or
property
doesn't support this method." I have varied the code to try .Value,
.DefaultValue as well as other more grasping (and less logical) options.
Seems like a fairly simple thing - can anyone help?

The form name is frmExhibitor
cboCompany has data fields of CompanyID, CompanyName, ContactID and
ContactFullName

Me.txtAltCompanyName.Value = Forms![frmExhibitors]!cboCompany.[Column(1)]
Me.txtAltContactFullName.Value =
Forms![frmExhibitors]!cboCompany.[Column(3)]

(The prefill functions for cboCompany and cboContact work just fine - it's
the alternate information that I can't get to autocomplete.)

Any help is appreciated!
 
A

Allen Browne

Good news. Solved.

I'm not sure if the web design changed, as I use Outlook Express to follow
the newsgroups. Under:
Tools | Accounts | News | Add | News
specify the News (NNTP) Server:
news.microsoft.com

In OE, you can mark and watch threads, and use Ctrl+H to filter your own
threads.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Pendragon said:
Allen,

Thank you very much. This works perfectly (of course!!). :)

BTW - I've noticed that when in the newsgroups and double-clicking on a
post, I used to be able to scroll through messages and then click on YES
for
a post answering my question or being helpful. Now when the new window
appears, the vertical scrollbar is missing and I am not able to review
subsequent posts NOR am I able to get to your post and mark your response
accordingly. Has the open post webpage design changed?

Anyway, thanks for your help as always.

Allen Browne said:
You really don't want to change the values every time the form is opened,
thus overwriting any previous entries that may have been made in
whichever
record happens to come up in the form.

Your subject suggests setting the Default Value, so perhaps something
like
this:

Private Sub Form_Open(Cancel As Integer)
If CurrentProject.AllForms("frmExhibitors").IsLoaded Then
With Forms("frmExhibitors")!cboCompany
If Not IsNull(.Value) Then
If .Column(1) <> vbnullstring then
Me.txtAltCompanyName.DefaultValue = """" & .Column(1)
&
""""
End If
If .Column(3) <> vbnullstring then
Me.txtAltContactFullName.DefaultValue = """" &
..Column(3) & """"
End If
End If
End With
End If
End Sub

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Pendragon said:
[Access 03]

I have a form with two combo boxes (cboCompany, cboContact) that are
prefilled based on selections from a superior form. There are two text
boxes
corresponding to these combo boxes for the user to enter alternate
names
for
both Company and Contact. I would like these to default to the values
in
the
combo boxes.

On my Form Open property I have the following code. My error message
is
either "You can't assign a value to this object" or "The object or
property
doesn't support this method." I have varied the code to try .Value,
.DefaultValue as well as other more grasping (and less logical)
options.
Seems like a fairly simple thing - can anyone help?

The form name is frmExhibitor
cboCompany has data fields of CompanyID, CompanyName, ContactID and
ContactFullName

Me.txtAltCompanyName.Value =
Forms![frmExhibitors]!cboCompany.[Column(1)]
Me.txtAltContactFullName.Value =
Forms![frmExhibitors]!cboCompany.[Column(3)]

(The prefill functions for cboCompany and cboContact work just fine -
it's
the alternate information that I can't get to autocomplete.)

Any help is appreciated!
 

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