|
|
Our Hot Pick: Rising Antivirus 2006 - Certified by TUV & Checkmark! Get 10% discount by entering this coupon code: ONDISCOUNT10
Hello Experts,
I need help.
First question: I have a main form (Clients) which allows user to select from a list of client ID's. A number of textboxes or fields get filled up. Now one of these textboxes is called Condition or the condition field. I now press a command buttopn which opens the orientation form. In the orientation form, I want to display records based on the text in the Condition field in the Clients form.
Here is copy of my code(I placed in form_load event of the orientation form). I don't know where to put it in the orientation_click event(command button on clients form) or in the form_load event for the orientation form.
--------------------------------------------------------------------------------------------------------------------------------- Private sub Form_Load Dim StrSearch As String
If Forms!Clients.Condition = GPM Then
StrSearch = "SELECT [Orientation Table].[Orientation Session Number], [Orientation Table].Date," StrSearch = StrSearch + " [Orientation Table].[Attendance Code]" StrSearch = StrSearch + " FROM [Orientation Table]" StrSearch = StrSearch + " WHERE ((([Orientation Table].[Orientation Session Number])<=2))"
DoCmd.RunSQL StrSearch
End If
End Sub
Also gives me errors: 'Error: Can't find the form clients referred to in microsgoft visual basic code. 'End if not structured properly
If can suggest some resources or list of books to look at, for beginning access vba programmers that would be great.
Thanks in advance
|
|
Since you're checking for a string value, you need quotes around the value. Since you're running the code in the module associated with the form, and since the control is on that form, you can use Me! instead of Forms!Clients:
If Me!Condition = "GPM" Then
I think that should solve the error you're getting.
Jeff Conrad has a list of references pointing to references to books at http://home.bendbroadband.com/conradsystems/accessjunkie/resources.html#Books
-- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no private e-mails, please)
"Data" <fahadahmad99[ at ]hotmail.com> wrote in message news:1153354751.141697.168890[ at ]h48g2000cwc.googlegroups.com...
[Quoted Text] > Hello Experts, > > I need help. > > First question: I have a main form (Clients) which allows user to > select from a list of client ID's. A number of textboxes or fields get > filled up. Now one of these textboxes is called Condition or the > condition field. I now press a command buttopn which opens the > orientation form. > In the orientation form, I want to display records based on the text > in the Condition field in the Clients form. > > Here is copy of my code(I placed in form_load event of the > orientation form). > I don't know where to put it in the orientation_click event(command > button on clients form) or in the form_load event for the orientation > form. > > --------------------------------------------------------------------------------------------------------------------------------- > Private sub Form_Load > Dim StrSearch As String > > If Forms!Clients.Condition = GPM Then > > StrSearch = "SELECT [Orientation Table].[Orientation Session > Number], [Orientation > Table].Date," > StrSearch = StrSearch + " [Orientation Table].[Attendance Code]" > StrSearch = StrSearch + " FROM [Orientation Table]" > StrSearch = StrSearch + " WHERE ((([Orientation Table].[Orientation > Session > Number])<=2))" > > DoCmd.RunSQL StrSearch > > End If > > End Sub > > Also gives me errors: > 'Error: Can't find the form clients referred to in microsgoft visual > basic code. > 'End if not structured properly > > If can suggest some resources or list of books to look at, for > beginning access vba programmers that would be great. > > Thanks in advance >
|
|
Douglas J. Steele wrote:
[Quoted Text] > Since you're checking for a string value, you need quotes around the value. > Since you're running the code in the module associated with the form, and > since the control is on that form, you can use Me! instead of Forms!Clients: > > If Me!Condition = "GPM" Then > > I think that should solve the error you're getting. > > Jeff Conrad has a list of references pointing to references to books at > http://home.bendbroadband.com/conradsystems/accessjunkie/resources.html#Books> > -- > Doug Steele, Microsoft Access MVP > http://I.Am/DougSteele> (no private e-mails, please) > > > "Data" <fahadahmad99[ at ]hotmail.com> wrote in message > news:1153354751.141697.168890[ at ]h48g2000cwc.googlegroups.com... > > Hello Experts, > > > > I need help. > > > > First question: I have a main form (Clients) which allows user to > > select from a list of client ID's. A number of textboxes or fields get > > filled up. Now one of these textboxes is called Condition or the > > condition field. I now press a command buttopn which opens the > > orientation form. > > In the orientation form, I want to display records based on the text > > in the Condition field in the Clients form. > > > > Here is copy of my code(I placed in form_load event of the > > orientation form). > > I don't know where to put it in the orientation_click event(command > > button on clients form) or in the form_load event for the orientation > > form. > > > > Hello David,
Thanks
But someone suggested another way, I don't know where to put the code though.
tina wrote: > well, i probably wouldn't filter (restrict) the records in the 2nd form's > Load event. since you're filtering based on data entered in a control in the > 1st form, it's easier to refer to that control from within that form; i'd > use the WHERE argument of the DoCmd.OpenForm action, in the Click event > procedure of the command button in the 1st form, as
> If Me!Condition = "GPM" Then > DoCmd.OpenForm "OrientationFormName", , , _ > "[Orientation Session Number]<=2" > Else > DoCmd.OpenForm "OrientationFormName" > End If
> substitute the correct form name, of course. note that the above places > quotes around "GPM" on the assumption that it is a text value in the 1st > form's control.
> hth
Thanks Tina.
Altough I am not sure why the code's not working. I placed it in the right location?
Private Sub cmdOrientation_Click()
If Me!Condition = "GPM" Then DoCmd.OpenForm "Orientation", , , _ "[Orientation Session number]<=2" Else DoCmd.OpenForm "Orientation" End If
'On Error GoTo Err_cmdOrientation_Click
' Dim stDocName As String ' Dim stLinkCriteria As String
' stDocName = "Orientation" ' DoCmd.OpenForm stDocName, , , stLinkCriteria
'Exit_cmdOrientation_Click: ' Exit Sub
'Err_cmdOrientation_Click: ' MsgBox Err.Description ' Resume Exit_cmdOrientation_Click
End Sub
|
|
Heck, I was so busy noticing the lack of quotes that I completely missed the fact that you're trying to use RunSQL with a SELECT query. You can't. RunSQL is only for Action queries (INSERT INTO, UPDATE, DELETE)
-- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele (no e-mails, please!)
"Douglas J. Steele" <NOSPAM_djsteele[ at ]NOSPAM_canada.com> wrote in message news:ud28QM5qGHA.4492[ at ]TK2MSFTNGP05.phx.gbl...
[Quoted Text] > Since you're checking for a string value, you need quotes around the
value. > Since you're running the code in the module associated with the form, and > since the control is on that form, you can use Me! instead of Forms!Clients: > > If Me!Condition = "GPM" Then > > I think that should solve the error you're getting. > > Jeff Conrad has a list of references pointing to references to books at > http://home.bendbroadband.com/conradsystems/accessjunkie/resources.html#Books > > -- > Doug Steele, Microsoft Access MVP > http://I.Am/DougSteele > (no private e-mails, please) > > > "Data" <fahadahmad99[ at ]hotmail.com> wrote in message > news:1153354751.141697.168890[ at ]h48g2000cwc.googlegroups.com... > > Hello Experts, > > > > I need help. > > > > First question: I have a main form (Clients) which allows user to > > select from a list of client ID's. A number of textboxes or fields get > > filled up. Now one of these textboxes is called Condition or the > > condition field. I now press a command buttopn which opens the > > orientation form. > > In the orientation form, I want to display records based on the text > > in the Condition field in the Clients form. > > > > Here is copy of my code(I placed in form_load event of the > > orientation form). > > I don't know where to put it in the orientation_click event(command > > button on clients form) or in the form_load event for the orientation > > form. > > > > -------------------------------------------------------------------------- ------------------------------------------------------- > > Private sub Form_Load > > Dim StrSearch As String > > > > If Forms!Clients.Condition = GPM Then > > > > StrSearch = "SELECT [Orientation Table].[Orientation Session > > Number], [Orientation > > Table].Date," > > StrSearch = StrSearch + " [Orientation Table].[Attendance Code]" > > StrSearch = StrSearch + " FROM [Orientation Table]" > > StrSearch = StrSearch + " WHERE ((([Orientation Table].[Orientation > > Session > > Number])<=2))" > > > > DoCmd.RunSQL StrSearch > > > > End If > > > > End Sub > > > > Also gives me errors: > > 'Error: Can't find the form clients referred to in microsgoft visual > > basic code. > > 'End if not structured properly > > > > If can suggest some resources or list of books to look at, for > > beginning access vba programmers that would be great. > > > > Thanks in advance > > > >
|
|
|