Open form based on criteria of another form.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a form I call QueryForm. On this form is a combo box that list all the
customers in the database. I need to open another form based on the selected
cutomer of that combo box. The form I am attempting to open is called
Query_by_Customer_Weekly_Form. Here is the code I am trying to use
(unsucessfully).

Private Sub SQLStatement1()
Dim strPara As String
strwhere = "[Query_by_Customer]![Customer]" = cmbCustName
DoCmd.OpenForm "[Query_by_Customer_Weekly_Form]", acViewNormal, , ,
strPara
End Sub

The Query_by_Customer_Weekly_Form pulls its data from the table via a query
called Query_by_Customer. Depending on what value is in the combo box
cmbCustName I need to populate the Query_by_Customer_Weekly_Form with all
records that contain that clients name. Any help is greatly appreciated.

C_Ascheman
 
Do you get an error message


' If the Customer field type is number then try
strwhere = "[Query_by_Customer]![Customer]" = cmbCustName
' If the Customer field type is string then try
strwhere = "[Query_by_Customer]![Customer] '" = cmbCustName & "'"

' You have one comma to match, try this
DoCmd.OpenForm "[Query_by_Customer_Weekly_Form]", acViewNormal , , strPara

Where the cmbCustName get the value from?
 
Sorry the equal sign should be inside the quote, with an & after the quote

' If the Customer field type is number then try
strwhere = "[Query_by_Customer]![Customer] =" & cmbCustName
' If the Customer field type is string then try
strwhere = "[Query_by_Customer]![Customer] = '" & cmbCustName & "'"

--
Good Luck
BS"D


Ofer Cohen said:
Do you get an error message


' If the Customer field type is number then try
strwhere = "[Query_by_Customer]![Customer]" = cmbCustName
' If the Customer field type is string then try
strwhere = "[Query_by_Customer]![Customer] '" = cmbCustName & "'"

' You have one comma to match, try this
DoCmd.OpenForm "[Query_by_Customer_Weekly_Form]", acViewNormal , , strPara

Where the cmbCustName get the value from?

--
Good Luck
BS"D


C_Ascheman said:
I have a form I call QueryForm. On this form is a combo box that list all the
customers in the database. I need to open another form based on the selected
cutomer of that combo box. The form I am attempting to open is called
Query_by_Customer_Weekly_Form. Here is the code I am trying to use
(unsucessfully).

Private Sub SQLStatement1()
Dim strPara As String
strwhere = "[Query_by_Customer]![Customer]" = cmbCustName
DoCmd.OpenForm "[Query_by_Customer_Weekly_Form]", acViewNormal, , ,
strPara
End Sub

The Query_by_Customer_Weekly_Form pulls its data from the table via a query
called Query_by_Customer. Depending on what value is in the combo box
cmbCustName I need to populate the Query_by_Customer_Weekly_Form with all
records that contain that clients name. Any help is greatly appreciated.

C_Ascheman
 
Thanks Ales and Ofer. Combining what both of you said I got it doing what I
need it to do perfectly. Here is the final working code:

Dim strPara As String
strPara = "[Query_by_Customer]![Customer]='" & cmbCustName & "'"
DoCmd.OpenForm "Query_by_Customer_Weekly_Form", acViewNormal, , strPara

Now to finish this program up. Finally I can see the light at the end of the
tunnel.

C_Ascheman



Ofer Cohen said:
Sorry the equal sign should be inside the quote, with an & after the quote

' If the Customer field type is number then try
strwhere = "[Query_by_Customer]![Customer] =" & cmbCustName
' If the Customer field type is string then try
strwhere = "[Query_by_Customer]![Customer] = '" & cmbCustName & "'"

--
Good Luck
BS"D


Ofer Cohen said:
Do you get an error message


' If the Customer field type is number then try
strwhere = "[Query_by_Customer]![Customer]" = cmbCustName
' If the Customer field type is string then try
strwhere = "[Query_by_Customer]![Customer] '" = cmbCustName & "'"

' You have one comma to match, try this
DoCmd.OpenForm "[Query_by_Customer_Weekly_Form]", acViewNormal , , strPara

Where the cmbCustName get the value from?

--
Good Luck
BS"D


C_Ascheman said:
I have a form I call QueryForm. On this form is a combo box that list all the
customers in the database. I need to open another form based on the selected
cutomer of that combo box. The form I am attempting to open is called
Query_by_Customer_Weekly_Form. Here is the code I am trying to use
(unsucessfully).

Private Sub SQLStatement1()
Dim strPara As String
strwhere = "[Query_by_Customer]![Customer]" = cmbCustName
DoCmd.OpenForm "[Query_by_Customer_Weekly_Form]", acViewNormal, , ,
strPara
End Sub

The Query_by_Customer_Weekly_Form pulls its data from the table via a query
called Query_by_Customer. Depending on what value is in the combo box
cmbCustName I need to populate the Query_by_Customer_Weekly_Form with all
records that contain that clients name. Any help is greatly appreciated.

C_Ascheman
 
I am attempting to do the same thing with a twist. I have a form that is
connected by ProjectID. Under Projects, we have tasks. On this form, there
is a command button that allows you to look at the tasks that are under the
specific project. On this subform, is a command button to add another task
to that particular project. I can get the form to come up as a blank form
but not with the ProjectID that it is to be added to. The user will not have
the option to choose which ProjectID to add it to, I want it to be automatic
from the previous form. The code is as follows:

Dim stLinkCriteria As String

DoCmd.GoToRecord acForm, Me.Name, acNewRec
stLinkCriteria = "[ProjectID]=" & Me!ProjectID

Ofer Cohen said:
Sorry the equal sign should be inside the quote, with an & after the quote

' If the Customer field type is number then try
strwhere = "[Query_by_Customer]![Customer] =" & cmbCustName
' If the Customer field type is string then try
strwhere = "[Query_by_Customer]![Customer] = '" & cmbCustName & "'"

--
Good Luck
BS"D


Ofer Cohen said:
Do you get an error message


' If the Customer field type is number then try
strwhere = "[Query_by_Customer]![Customer]" = cmbCustName
' If the Customer field type is string then try
strwhere = "[Query_by_Customer]![Customer] '" = cmbCustName & "'"

' You have one comma to match, try this
DoCmd.OpenForm "[Query_by_Customer_Weekly_Form]", acViewNormal , , strPara

Where the cmbCustName get the value from?

--
Good Luck
BS"D


C_Ascheman said:
I have a form I call QueryForm. On this form is a combo box that list all the
customers in the database. I need to open another form based on the selected
cutomer of that combo box. The form I am attempting to open is called
Query_by_Customer_Weekly_Form. Here is the code I am trying to use
(unsucessfully).

Private Sub SQLStatement1()
Dim strPara As String
strwhere = "[Query_by_Customer]![Customer]" = cmbCustName
DoCmd.OpenForm "[Query_by_Customer_Weekly_Form]", acViewNormal, , ,
strPara
End Sub

The Query_by_Customer_Weekly_Form pulls its data from the table via a query
called Query_by_Customer. Depending on what value is in the combo box
cmbCustName I need to populate the Query_by_Customer_Weekly_Form with all
records that contain that clients name. Any help is greatly appreciated.

C_Ascheman
 

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

Back
Top