473,657 Members | 2,409 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling A Combobox Value in VBA Code

1 New Member
Hello,

I am using Access 2007, but need to be compatible with 2003. I am importing a sheet from Excel into Access (code below). I would like the sheet name to be determined from a drop down on a form instead of being hard coded. So the user would select the sheet name from the drop down, click Import, and the VBA would import the tab the user selected. Also, different tabs would need to be imported to different tables. Is there a way to make the table name dependent on the tab selected?

I'm attempting to use the same function instead of having it repeated a bunch of times with only two small variables changed.

Thanks!

Expand|Select|Wrap|Line Numbers
  1. Option Compare Database
  2. '------------------------------------------------------------
  3. ' Import
  4. '
  5. '------------------------------------------------------------
  6. Function Import()
  7. Dim sFilename As Office.FileDialog
  8.  
  9. Set dlgOpen = Application.FileDialog(dialogtype:=msoFileDialogOpen)
  10.  
  11. With dlgOpen
  12.     .AllowMultiSelect = False
  13.     .Show
  14. End With
  15.  
  16. If dlgOpen.SelectedItems.Count = 0 Then Exit Function
  17. sPath = dlgOpen.SelectedItems.Item(1)
  18.  
  19. On Error GoTo Import_Err
  20.  
  21.     DoCmd.SetWarnings False
  22.     DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "tempTblWeeklyPipeline", sPath, True, "SAP OM Active$"
  23.     DoCmd.SetWarnings True
  24.     MsgBox "Import Complete"
  25.  
  26. Import_Exit:
  27.     Exit Function
  28.  
  29. Import_Err:
  30.     MsgBox Error$
  31.     Resume Import_Exit
  32.  
  33. End Function
Jul 31 '07 #1
1 2681
MMcCarthy
14,534 Recognized Expert Moderator MVP
Set the tablename to a variable and use a case statement to set the value dependent on the tab.

If you need it to be compatible in 2003 then design it in 2003 not 2007. The backwards compatibility from 2007 to 2003 is not good.
Aug 6 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
1523
by: Dianna K | last post by:
Hi, I am trying to set the value of the a combobox with a field from a dataset. It will not set. Me.cboTypeDesc.Text = DsTitle.Tables("Title").Rows(0).Item ("genre_description") or
1
7547
by: Goos van Beek | last post by:
Hello. I'm using the following code to fill a combobox on a Windows form: private void FillCboRelation(){ using(SqlCommand sqlStatement = new SqlCommand("sp_RelationList",cnn)) { using(SqlDataReader rdReader=sqlStatement.ExecuteReader()){ while(rdReader.Read()){ cboRelation.Items.Add(rdReader.ToString()); }//end while
9
7505
by: juli jul | last post by:
Hello ,I am trying to get the comboBox value but when I am writing: MessageBox.Show(this.comboBoxdb.SelectedValue.ToString()); I get the following result: System.Data.DataRowView instead of the selected value . Why? *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!
2
9170
by: Kevin Hodgson | last post by:
I have a DataBound ComboBox, which has a text value as the Value property, and the UniqueID for that value is bound to the Combobox.Tag property. When a user makes a new selection in the combobox, I need to run a SQL Query with the UniqueID of the new value they are picking. The .SelectedIndexChanged and .SelectedValueChanged events give me the .Tag value BEFORE the new selection is made. I'm getting the value for the previous value,...
0
1815
by: zhuang | last post by:
Hi, Adding combobox to datagrid has been posted many times. I have a datagrid which has multiple combobox columns and normal textbox columns. But how could I change other combo box values at the same row when user change the value of one of the combo box. The textbox value in the same row could be changed by modifying the
1
1885
by: exxcusemee | last post by:
Hi to all, Basically my problem is that that i am trying to set the value of combobox.But problem is i dont have value of combobox.Whatever i have is the label which will render to the user whenever he/she fills the form.Actually value of the combo is unique ID that refers the master from where the value is coming. I want to set the value of combo.But i have only label.What should i do ??
0
2051
by: Randy | last post by:
Hi, I have some comboboxes that are created dynamically at run time based on user actions. I found a procedure on a message board to autofill the combobox text from the dataview that the comboboxes are bound to. It works perfectly on the comboboxes that I have created at design time, but the ones that I create runtime behave differently. The problem is that when the user tabs onto the combobox, the box stays blank, which is fine. ...
3
1449
by: rhepsi | last post by:
Hii all, How to join two tables and a combobox value?? i have 2 combo boxes and 2 tables i have aquery: 1) Dim myselectquery As String = "SELECT pr_project_id_pk FROM tbl_projects WHERE tbl_projects.pr_project_location= ?SName"
1
2184
by: sjarmy | last post by:
I am using javascript to make a dropdownlist act like a combobox and it is work well. The issue I'm having is when the user types in the combobox and finds the selection he wants, he has to use the mouse to make the actual selection. The user wants to have the option of just hitting the enter key instead of using the mouse. He also wants to use the tab key to move to the next field. I'm using onkeydown to call the javascript, and I know I need...
0
8395
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8826
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7330
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4306
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1955
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.