Running SQL inside forms

MS Office Access

    Next

  • 1. SetFocus Problems
    I am using Access 03 i have a form with a cmd button on that once it is click bring up the find dialog box. I am trying to set focus on field call "PONumber", but i keep getting "Object doesn't support this propertly or method" Here is the code: Private Sub cmdFindPO_Click() 'Set focus on the PO number field On Error GoTo Err_cmdFindPO_Click Me![PONumber].SetFocus DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70 Exit_cmdFindPO_Click: Exit Sub Err_cmdFindPO_Click: MsgBox Err.Description Resume Exit_cmdFindPO_Click End Sub Thanks for your value help! -- Coach K "Knowledge is Power"
  • 2. TransferSpreadsheet Errors
    In my code, I'm using TransferSpreadsheet and all is working fine. However, should the spreadsheet contain an error, a table is created within my Acc2007 database containing any errors that ocurred. Although this is nice to have, I'm worried that I'll end up with countless error tables after awhile. Is there a switch I can use or a parameter I can set to prevent this table from being created? (The data is useless.) I guess I can also look for an error-table after the TransferSpreadsheet executes and delete it (although the error-table name changes based upon the worksheet name which migh make it difficult to do so.)

Running SQL inside forms

Postby Steven Scaife » Fri, 05 Nov 2004 20:46:15 GMT

How do you create a recordset inside a form

I have

dim rs as recordset

 strSQL = "SELECT Time_Of_Appointment FROM Appointment WHERE Agent_ID = " & 
Agent_ID.Value

    Set rs = DoCmd.RunSQL(strSQL)

but it errors saying expected function or variable.

I am used to doing this in ASP but cant figure out why in access.

any help would be much appreciated 



RE: Running SQL inside forms

Postby RGF2aWQgTGVhaHk » Fri, 05 Nov 2004 21:29:05 GMT

Hey Steve,

Use the DAO object library to do this

In the VBA window, select Tools - Refrences and tick Microsoft DAO Object 
Library from the list if its not already done so...

then do it like this

Dim db as dao.database
dim rs as dao.recordset
dim strSQL as string

set db = currentdb

strSQL = "SELECT Time_Of_Appointment FROM Appointment WHERE Agent_ID = " & 
Agent_ID.Value

set rs = db.openrecordset(strSQL)

you can now use the recordset..

example:

while not rs.eof
   debug.print rs("Time_Of_Appointment").value
   rs.movenext
wend

Dave






Similar Threads:

1.appear or add more form inside form , or inserting more textfield inside form

2.Running Form based module inside of macro

RE: Access 2003

On frmMain, I have a command button that has a module for the click
event: 'Private Sub cmdRunQuery_Click().
frmMain also has an option group called "optQueryCriteria" which has
four different options for the 'condition' for the single block of SQL
that runs from the command buttons' click event.
Right now the user checks one of the four options from
optQueryCriteria, then clicks the "Run Query" button to get their
result.

In order to de-clutter my screen, I would like to transfer this logic
to have a menu option called "File/Queries", then inside of that menu
option have the four listed as options.

When I first investigated this,  it seemed as though custom menu
options only allowed macros to be run from the command button, not
Private Subs that resided inside of a form.  Having learned that, I am
stumped as to how I can get cmdRunQuery_Click() to fire within a
macro.  Do I have to make it a Public Sub inside of a standalone
module object?

Secondly, I'm having trouble nesting choices inside of custom menus.
It's been ages since I last used custom menus for my apps because my
apps are all in-house small corporate apps.  (custom menus were so
easy to set up in VB6)
I'd like to have File...then dropping down inside of that have
"Search", then "Queries", then inside of "Queries", have "Query1,
Query2, Query3, Query4".  Right now all of these menu options are at
the highest level of the menu bar and are not nested.

3.Using SQL inside a Form

Hello,

I have a form that has two fields in it (FILE NUMBER and CASE NUMBER) - I 
would like to set up the form so that when the form loads, it queries the 
PERSON table for those two parameters, then retrieves the First and Last 
name from the PERSON table, deletes all the records from another table 
called PERSON_DROPDOWN, and then inserts the First and Last name values into 
that PERSOn_DROPDOWN table. Any ideas? 


4.refer to a form's text box.text inside a SQL clause

On 16 Feb, 15:03, "giannis" < XXXX@XXXXX.COM > wrote:
> How can i refer to a form's textbox.text inside a SQL clause ?
>
> I know how is that in Access* but at VB i receive error.
>
> * SELECT FIELD1 FROM TABLE1
>    WHERE TABLE1.FIELD2=[FORMS]![TEXTBOX].[NAME]


Hi Giannis try this

Dim strwhereclause as string  =textbox1.text

SELECT FIELD1 FROM TABLE1 WHERE TABLE1.FIELD2= " ' " + strwhereclause
+" ' "

OR

SELECT FIELD1 FROM TABLE1 WHERE TABLE1.FIELD2= " ' " + textbox1.text
+" ' "

Thanks

Adam

5.refer to a form's text box.text inside a SQL clause

How can i refer to a form's textbox.text inside a SQL clause ?

I know how is that in Access* but at VB i receive error.

* SELECT FIELD1 FROM TABLE1
   WHERE TABLE1.FIELD2=[FORMS]![TEXTBOX].[NAME] 


6. child form inside the page

7. Creating 2nd transaction form inside db ?

8. displaying a form inside a report.



Return to MS Office Access

 

Who is online

Users browsing this forum: No registered users and 16 guest