Could some one please Help! Sorry no one answered my question.

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 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
 
D

Douglas J. Steele

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
 
D

Data

Douglas said:
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

Hello David,

Thanks

But someone suggested another way, I don't know where to put the code
though.

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.

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
 
D

Douglas J. Steele

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

(no e-mails, please!)


Douglas J. Steele said:
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

(no private e-mails, please)


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 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
 

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