473,503 Members | 2,173 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 2671
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
1514
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
7530
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)) {...
9
7494
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...
2
9154
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...
0
1803
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...
1
1872
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...
0
2042
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...
3
1443
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...
1
2172
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...
0
7205
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,...
0
7093
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
7287
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
5594
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,...
1
5022
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4688
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...
0
1521
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 ...
1
746
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
399
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...

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.