Duane,
Yes I wanted to see the results of the sql. I think that the code finally works. I am not sure what was wrong. but I think it was the query def.
Thank You Very Much.
Jim Wagner
On Tuesday, February 19, 2019, 4:10:31 PM MST, Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:
Jim,
I think the errors and questions obscured the main issue. DoCmd.OpenQuery expects a saved query, not an SQL string.
Can we assume you want to view the results of the SQL statement in datasheet view? If so, I suggest you create a new query with any SQL view you choose since it will be replaced with your code.
Then use code like:
Dim strSQL As String
DoCmd.OpenQuery strQueryName, acViewNormal, acReadOnly
Dim db As DAO.Database
Dim qd as DAO.QueryDef
Dim strQueryName as String
strQueryName = "[Your new saved query Name here]"
Set db = CurrentDb
Set qd = db.QueryDefs(strQueryName)
strSQL = "SELECT [Position Nbr], * FROM AccountCodesForTimesheets " & _
"WHERE [Position Nbr]='" & Me.[txtPosCd] & "'"
debug.Print strSQL
qd.SQL = strSQL
From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of Jim Wagner luvmymelody@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
Sent: Tuesday, February 19, 2019 3:42 PM
To: Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals]
Subject: Re: [MS_AccessPros] Re: Open a recordset question
Sent: Tuesday, February 19, 2019 3:42 PM
To: Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals]
Subject: Re: [MS_AccessPros] Re: Open a recordset question
- The text box is an unbound text box
- I tried the code and I get different errors.
- the first from the button I get the can't find the select statement but the immediate window has the select statement results and the highlighted code is DoCmd.OpenQuery strSQL, acViewNormal, acReadOnly
- from the immediate window I get the sub function not defined
- It compiled and no errors
- tried using the me.txtPosCd and I get the same error as cant find the Select statement
- the immediate window has
- Command32
SELECT AccountCodesForTimesheets.[Position Nbr], * FROM AccountCodesForTimesheets WHERE [Position Nbr]= '109153'
Jim Wagner
On Tuesday, February 19, 2019, 2:32:47 PM MST, Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:
Jim,
- Data Type of the field...?
- Did you try the suggested code?
- Did it compile?
- Did you get an error?
- Did you try use Me. in place of [Forms]![frmAccountCodesForTimesheetsValidationForm]!?
- What is displayed in the debug window?
Regards,
Duane
From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of Jim Wagner luvmymelody@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
Sent: Tuesday, February 19, 2019 3:29 PM
To: Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals]
Subject: Re: [MS_AccessPros] Re: Open a recordset question
Sent: Tuesday, February 19, 2019 3:29 PM
To: Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals]
Subject: Re: [MS_AccessPros] Re: Open a recordset question
there is a button running the code from the frmAccountCodesForTimesheetsValidationForm
Jim Wagner
On Tuesday, February 19, 2019, 2:12:51 PM MST, Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:
Jim,
There is no "Plain Text" data type. There is Short Text and Long Text as well as many numeric and date data types.
If the [Position Nbr] field is any type of text, try:
strSQL = "SELECT AccountCodesForTimesheets.[Position Nbr], * FROM AccountCodesForTimesheets " & _
"WHERE [Position Nbr]= '" & [Forms]![frmAccountCodesForTimesheetsValidationForm]![txtPosCd] & "'"
You never suggested whether the code was running from frmAccountCodesForTimesheetsValidationForm or elsewhere.
Regards,
Duane
From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of Jim Wagner luvmymelody@yahoo.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
Sent: Tuesday, February 19, 2019 3:06 PM
To: Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals]
Subject: Re: [MS_AccessPros] Re: Open a recordset question
Sent: Tuesday, February 19, 2019 3:06 PM
To: Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals]
Subject: Re: [MS_AccessPros] Re: Open a recordset question
the text box is Plain Text
Jim Wagner
On Tuesday, February 19, 2019, 1:10:20 PM MST, Duane Hookom duanehookom@hotmail.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com> wrote:
Good call Doyce. Even seasoned Access developers have issues with recordsets that must set the parameters.
strSQL = "SELECT AccountCodesForTimesheets.[Position Nbr], * FROM AccountCodesForTimesheets " & _
"WHERE [Position Nbr]= " & [Forms]![frmAccountCodesForTimesheetsValidationForm]![txtPosCd]
Debug.Print strSQL ' let me see what you got!
Set rs = CurrentDb.OpenRecordset(strSQL)
DoCmd.OpenQuery strSQL, acViewNormal, acReadOnly
DoCmd.OpenQuery strSQL, acViewNormal, acReadOnly
If the code is running in frmAccountCodesForTimesheetsValidationForm then you can simply use:
Me.txtPosCd
This all assumes [Position Nbr] is numeric. That's why Doyce asked.
Regards,
Duane
From: MS_Access_Professionals@yahoogroups.com <MS_Access_Professionals@yahoogroups.com> on behalf of winberry.doyce@con-way.com [MS_Access_Professionals] <MS_Access_Professionals@yahoogroups.com>
Sent: Tuesday, February 19, 2019 2:04 PM
To: MS_Access_Professionals@yahoogroups.com
Subject: [MS_AccessPros] Re: Open a recordset question
Sent: Tuesday, February 19, 2019 2:04 PM
To: MS_Access_Professionals@yahoogroups.com
Subject: [MS_AccessPros] Re: Open a recordset question
Jim,
Try putting Debug.print strSQL right under your SQL statement. Then you can see how Access is interpreting your SQL statement. It will show in the immediate window. I suspect you need to change your where statement to something like this depending on what type of data is in your txtPosCd on your form.
WHERE (((AccountCodesForTimesheets.[Position Nbr])= "'" & [Forms]![frmAccountCodesForTimesheetsValidationForm]![txtPosCd] & "'"));"
What type of data is txtPosCD?
Doyce Winberry
---In MS_Access_Professionals@yahoogroups.com, <luvmymelody@...> wrote :
Hello all,
I seemingly need to do something really simple but I have spent 5 hours on this. searching the internet for solutions. But nothing helps me.
I am trying to open a recordset or even just a table with criteria from a form.
__._,_.___
Posted by: Jim Wagner <luvmymelody@yahoo.com>
Reply via web post | • | Reply to sender | • | Reply to group | • | Start a New Topic | • | Messages in this topic (14) |
Have you tried the highest rated email app?
With 4.5 stars in iTunes, the Yahoo Mail app is the highest rated email app on the market. What are you waiting for? Now you can access all your inboxes (Gmail, Outlook, AOL and more) in one place. Never delete an email again with 1000GB of free cloud storage.
SPONSORED LINKS
.
__,_._,___
Tidak ada komentar:
Posting Komentar