Question #9350017

how can I pull value directly from a table from a command using VBA code?

I need to access a value directly from a table using VBA code, but first I need to select a value from a drop down box in a pivot table. The box is called "CITY" and when it drops it has a bunch of citys and I need to select "Austin" only so that I can pull the correct data from my example below. How do I add this step in VBA? I have been trying to find this out via web for two hours. Thanks for help! I opened a new module 1st. I created a function called GetGST that retrieves the GST field from a table called GST. I need to write a code in here that says select “austin” from this box out of all the choices in the drop down box. Here is where I am now, but havnt added anything on what I am asking Function GetGST() As String Dim db As Database Dim Lrs As DAO.Recordset Dim LSQL As String Dim LGST As String 'Open connection to current Access database Set db = CurrentDb() 'Create SQL statement to retrieve value from GST table LSQL = "select GST from GST" Set Lrs = db.OpenRecordset(LSQL) 'Retrieve value if data is found If Lrs.EOF = False Then LGST = Lrs("GST") Else LGST = "Not found" End If Lrs.Close Set Lrs = Nothing GetGST = LGST End Function

2013-08-08 14:49:35

TELL US , if you have any answer

There is NEVER a problem, ONLY a challange!

The is a free-to-use knowledgebase.
  The was started on: 02.07.2010.
  It's free to register. Once you are a registered user, you can ask questions, or answer them.
  (Unless registration you can just answer the questions anonymously)
  Only english!!! Questions and answers in other languages will be deleted!!

Cheers: the PixelFighters


C'mon... follow us!

Made by, history, ect.