473,394 Members | 2,020 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Open form using where clause

Hi,

Simple version of the question.....

How do I use the where clause of the open form command to show an
account with a matching ID to be displayed when the form is opened?

Eg. I select a record on a continuous form and click and edit button.
The button runs the open form code. I want the APPID of the current
record on the continous form to match the APPID of the record viewed
on the new form to be opened.

Complex version of the question;

I have a form - FRMAPPOINTMENTS with entries stored in a table,
TBLAPPOINTMENTS. I have a query based on this table QRYAPPOINTMENTS,
and a continuous form based on this query - FRMQUERYAPPOINTMENTS.
(There is some (probably flawed!) logic behind this bizarre setup).

I want to select a record in the continous form FRMQUERYAPPOINTMENTS
and by clicking on an edit button on this form to open the form
FRMAPPOINTMENTS at the corresponding record. The matching fields are
the APPID in both forms.

I have tried numerous where clauses in the openform command and having
no luck.

Thanks,

Mar 23 '07 #1
14 24962
keri wrote:
Hi,

Simple version of the question.....

How do I use the where clause of the open form command to show an
account with a matching ID to be displayed when the form is opened?

Eg. I select a record on a continuous form and click and edit button.
The button runs the open form code. I want the APPID of the current
record on the continous form to match the APPID of the record viewed
on the new form to be opened.

Complex version of the question;

I have a form - FRMAPPOINTMENTS with entries stored in a table,
TBLAPPOINTMENTS. I have a query based on this table QRYAPPOINTMENTS,
and a continuous form based on this query - FRMQUERYAPPOINTMENTS.
(There is some (probably flawed!) logic behind this bizarre setup).

I want to select a record in the continous form FRMQUERYAPPOINTMENTS
and by clicking on an edit button on this form to open the form
FRMAPPOINTMENTS at the corresponding record. The matching fields are
the APPID in both forms.

I have tried numerous where clauses in the openform command and having
no luck.

Thanks,
var = "Smith"
"ID = """ & var & """

var = 1
"ID = " & var

var = Date
"ID = #" & var & "#"

Let's say you have a field called ID in FRMQUERYAPPOINTMENTS. The ID of
the current record is the ID number you want to open in FRMAPPOINTMENTS.
Remember, strings are surrounded by quotes, dates by #, and numbers
with nothing

Docmd.OpenForm "FRMAPPOINTMENTS",,,"ID = " & Me.ID

Mar 23 '07 #2
Thanks for the reply. However I recieve an error;

Run time error 3075

Syntax error (missing operator) in expression "APPID =" & Me.APPID

Sorry for being fairly useless.

Mar 24 '07 #3
I have had another thought on this - the form I am trying to open has
a subform (which is the only bit I need to view), however the subform
entries are based on a selection from the main form hence the reason I
cannot view the appointment in the subform.

So, I have created another appointments form based on the appointments
table. So I have changed my open form command line thingy to;

DoCmd.OpenForm "APPOINTMENTS", , , "APPID = " & Me.APPID

I now get;

Run time error 2501

The openform action was cancelled
Mar 24 '07 #4
I now have this;

DoCmd.OpenForm "appointments", , , "appid = 'me.appid'"

which opens the form, but the record I wish to dsplay (with the
matching APPID as the APPID of the selected record in the query) is
not displayed - the form is blank although shows filtered next to the
record selector at the bottom of the screen.

Could this be because I cannot refer to a selected APPID in the query
as me.APPID?
Mar 24 '07 #5
keri wrote:
I have had another thought on this - the form I am trying to open has
a subform (which is the only bit I need to view), however the subform
entries are based on a selection from the main form hence the reason I
cannot view the appointment in the subform.

So, I have created another appointments form based on the appointments
table. So I have changed my open form command line thingy to;

DoCmd.OpenForm "APPOINTMENTS", , , "APPID = " & Me.APPID

I now get;

Run time error 2501

The openform action was cancelled

The form's OnOpen event has a Cancel property.
Private Sub Form_Open(Cancel As Integer)

If you set Cancel = True in the OnOpen event, it will return control
back to the calling form and give you a 2501 error.

I am unsure why you need another subform. Unless the subform makes
references to the main form in its code or recordsource, you should be
able to call the subform by itself.

Can you open the old subform by itself (from the database window)? Can
you open the new form by itself?

If so, ensure you are attempting to filter on the correct fields.

If worse gets to worse, open up the form and on the line to OpenForm,
press your mouse on the left window column of the code (a red circle
will be displayed) and step thru the code process.
Mar 24 '07 #6
I am now here and very frustrated!

Private Sub Command13_Click()
Dim thisid
Set thisid = Me.APPID
Debug.Print thisid

DoCmd.OpenForm "appointments", , , "appid = 'thisid'"

End Sub

This opens the form but does not show the correct record (once again
the record is blank but the form says filtered). I entered the print
line to see if it was assigning the correct value to the thisid
variable, and it is, yet this is obviously not being passed to the
openform filter.

If I use this line;

DoCmd.OpenForm "appointments", , , "appid = '13'"

Then the form opens with the correct appid record showing.

So why will it print thisid variable as 13 but not use this as the
filter value for the openform command?

Grrrrr!!!!

Mar 24 '07 #7
On 24 Mar 2007 07:57:41 -0700, "keri" <ke********@hotmail.comwrote:
>I am now here and very frustrated!

Private Sub Command13_Click()
Dim thisid
Set thisid = Me.APPID
Debug.Print thisid

DoCmd.OpenForm "appointments", , , "appid = 'thisid'"

End Sub

This opens the form but does not show the correct record (once again
the record is blank but the form says filtered). I entered the print
line to see if it was assigning the correct value to the thisid
variable, and it is, yet this is obviously not being passed to the
openform filter.

If I use this line;

DoCmd.OpenForm "appointments", , , "appid = '13'"

Then the form opens with the correct appid record showing.

So why will it print thisid variable as 13 but not use this as the
filter value for the openform command?

Grrrrr!!!!
It appears appid is a text value therefore it needs to be surrounded on quotes
in your criteria.

DoCmd.OpenForm "appointments", , , "appid = " & Chr(34) & me.appid & Chr(34)

Wayne Gillespie
Gosford NSW Australia
Mar 24 '07 #8
I now get a compile error "Can't find project or library" and on debug
the Chr is highlighted!
DoCmd.OpenForm "appointments", , , "appid = " & Chr(34) & me.appid & Chr(34)
It seems i'm in a rut here!

Mar 24 '07 #9
keri wrote:
I now get a compile error "Can't find project or library" and on debug
the Chr is highlighted!

>>DoCmd.OpenForm "appointments", , , "appid = " & Chr(34) & me.appid & Chr(34)


It seems i'm in a rut here!
I think you are having a case of bad kharma. Or perhaps your computer
is out to get you for banging the keyboard.

Open up a code module. Then from the menu click tools/references. In
my case I have Visual Basic For Applications, Microsoft Access Library
(ver#), and Microsoft DAO in that order.

CHR() is an Access function to return a character string of the Ascii value.

Wayne's example explicity surrounds your value in quotes.

In prior examples you were surrounding the whole string in quotes...
"appid = 'thisid'"
This will never work unless you want to compare appid to the value "this
id". You really want to compare it to the variable's value.

Mar 24 '07 #10
Thanks everybody,

I think it was the computer (once I had been given correct code I knew
I couldn't go on blaming myself!) . I now have the code supplied to me
working just perfectly. I had to restart the PC for some reason - but
then I knew it was sick in the first place, and it loves to make my
life difficult!
Private Sub Command13_Click()
Dim thisid
Dim frm As Form

Set thisid = Me.APPID
Debug.Print thisid

DoCmd.OpenForm "appointments", , , "appid = " & Chr(34) & Me.APPID &
Chr(34)
DoCmd.Close acForm, "appointments query", acSaveYes
End Sub

Mar 24 '07 #11
keri wrote:
Thanks everybody,

I think it was the computer (once I had been given correct code I knew
I couldn't go on blaming myself!) . I now have the code supplied to me
working just perfectly. I had to restart the PC for some reason - but
then I knew it was sick in the first place, and it loves to make my
life difficult!
Private Sub Command13_Click()
Dim thisid
Dim frm As Form

Set thisid = Me.APPID
Debug.Print thisid

DoCmd.OpenForm "appointments", , , "appid = " & Chr(34) & Me.APPID &
Chr(34)
DoCmd.Close acForm, "appointments query", acSaveYes
End Sub
That's good.

One comment. If your application is a small and minor one, you can
ignore my comment. Heck, you can ignore it all together regardless.

When you create a control, why use the default name supplied by the
wizard? Ex: Command13. I think it's easy to give it the name
"CommandOpenAppointments"...simply open the property sheet. When
looking at your code a verbose CommandOpenAppointments provides far more
detail about its purpose than Command13. Same with any control
receiving input or mouse presses. About the only thing I leave alone is
the Label or Line controls since I rarely have need to specify
them...unless I need to change their caption.

Mar 24 '07 #12
After a long day and night of this you have almost lost me completely.
But right now I want to marry you as you know what you're talking
about and I don't have a clue!

I wish I had the time and money to commit myself to learning this
stuff inside out and back to front!

Basically this comment is to say thanks to all of the people that did,
and who help people like me who are fairly hopeless!

Mar 24 '07 #13
Ps. Why Salad? Is that your actual name?

Mar 24 '07 #14
keri wrote:
Ps. Why Salad? Is that your actual name?
No. :-).

I used to post with my real name. I also post in political newsgroups.
I must have made someone mad at one point in the political group due
to an attack I had on my account. I also thought I was getting spam
from people that harvest email accounts from newsgroups.

Salad is a non-descript name and a salad is healthy and good. In
another venue I've adopted the name CeasarSalad.

Remember to eat your vegetables.

Bye
Mar 25 '07 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: John | last post by:
Just a general question... I'm currently using a combobox that when updated, opens a form with its recordset based on a query using the combo box value as the criteria. I'm I correct in...
4
by: Dalan | last post by:
I presume that using an open recordset method is the preferred method of accomplishing what I'm trying to do. Of course, if there are other options that would work, feel free to share them. I...
15
by: Tony Williams | last post by:
I have two forms, frma and frmb, both are for inputting new records and are based on a table, tblmonth, both have two controls, txtmonth and txtmonthlabela which are based on the fields in the...
1
by: petersk | last post by:
Firstly I am an older person trying to teach myself to create a project and teach myself Access VBA programming along the way. I anticipate a number of problems I will need help with but here...
2
by: allyn44 | last post by:
Hello, I have built a serch form for users to edit records. I only want them to pull up the record they need, and I want to check for nulls. There should not be dupes becasue the underlying...
29
by: Bryce K. Nielsen | last post by:
Suddenly this week, I've started getting this error message: System.Data.SqlClient.SqlConnection(GetOpenConnection)ExecuteNonQuery requires an open and available Connection. The connection's...
3
by: Cagey | last post by:
What I'm trying for: If this selection or if click on selection (highlighted line choice/ which ever selection change) w/in query's combo dropdown list box (on Switchboard), then Open in...
4
by: magmike | last post by:
I've created a report for the purpose of printing a one page summary of a record. Of course, when I created the report, it gives me a page on every record. Can I create a button to open that report...
4
by: nottarealaddress | last post by:
I'm trying to get my feet wet in VB2005 (our new standard at work after officially stopping new development in VB6 about a month ago). I'm working with a simple sql 2005 table of 50 entries, one...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.