Please help.Need help with syntax. Restricting entries based on user's selection from a combobox.

  • Thread starter Thread starter Data
  • Start date Start date
D

Data

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 button 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 microsoft 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
 
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
 
tina said:
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
Data said:
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 button 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 microsoft 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
 
well, "the code's not working" doesn't tell me anything useful. since i
can't see your computer or database, you'll have to describe what happens
when you click the button so i can attempt to troubleshoot.

hth


Data said:
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
Data said:
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 button 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 microsoft 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
 
Back
Top