473,320 Members | 1,853 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Convert to ADO from DAO Method

9
Dear All,
Good Morning first.

I have code in DAO Method such as
Expand|Select|Wrap|Line Numbers
  1. Function delete_tb(name_of_table)
  2. Dim rs1 As Recordset
  3. Dim db As DAO.Database
  4.  
  5. Set rs1 = CurrentDb.OpenRecordset("SELECT MSysObjects.Name" _
  6.     & " FROM MSysObjects WHERE MSysObjects.Type= 1 And MSysObjects.Flags=0" _
  7.     & " and MSysObjects.Name='" & name_of_table & "'")
  8.  
  9.     If Not rs1.EOF Then
  10.         Set db = CurrentDb
  11.         db.TableDefs.Delete name_of_table
  12.         db.Close
  13.         Set db = Nothing
  14.     End If
  15.  
  16.     rs1.Close
  17.     Set rs1 = Nothing
  18.  
  19. End Function
  20.  
How to write the function above in ADODB Method?
thanks
Jun 10 '14 #1

✓ answered by twinnyfo

n3wkid,

You actually have everything you need, you just need to put it all together:

Expand|Select|Wrap|Line Numbers
  1. Public Sub DeleteTable(TableName)
  2.     Dim strTable As String
  3.     strTable = Nz(DLookup("[Name]", "MSysObjects", _
  4.         "[Type] = 1 And Flags = 0 And Name='" & TableName & "'"), "")
  5.     If Not strTable = "" Then
  6.         DoCmd.DeleteObject acTable, TableName
  7.     End If
  8. End Sub
Hope this hepps!

7 1238
twinnyfo
3,653 Expert Mod 2GB
n3wkid,

You could accomplish this rather easily using the following code:

Expand|Select|Wrap|Line Numbers
  1.     If Not rs1.EOF Then 
  2.         DoCmd.DeleteObject acTable, name_of_table 
  3.     End If
This might solve the problem.

Please let me know if that hepps!
Jun 10 '14 #2
n3wkid
9
twinnyfo,

I have face error..and I don't understand full to change it
with ADO

maybe you can totally re write if you want to help me?
Jun 11 '14 #3
twinnyfo
3,653 Expert Mod 2GB
You could also do this without using a record set of any kind. Just use a dlookup function to find the name of the table in MySysObjects. I'll take a look at this and try to send a quick sub that you could use. I am sure it's fairly simple.
Jun 11 '14 #4
n3wkid
9
thanks so much..I waiting this..
Jun 11 '14 #5
twinnyfo
3,653 Expert Mod 2GB
n3wkid,

You actually have everything you need, you just need to put it all together:

Expand|Select|Wrap|Line Numbers
  1. Public Sub DeleteTable(TableName)
  2.     Dim strTable As String
  3.     strTable = Nz(DLookup("[Name]", "MSysObjects", _
  4.         "[Type] = 1 And Flags = 0 And Name='" & TableName & "'"), "")
  5.     If Not strTable = "" Then
  6.         DoCmd.DeleteObject acTable, TableName
  7.     End If
  8. End Sub
Hope this hepps!
Jun 11 '14 #6
n3wkid
9
Thank you so much... :)
Jun 11 '14 #7
twinnyfo
3,653 Expert Mod 2GB
Glad I could help. Let us know if you come across any more stumbling blocks and we'll do what we can to help!
Jun 11 '14 #8

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

Similar topics

2
by: William Stacey | last post by:
Example line: string temp = Convert.ToString(null); Convert.ToString() says it will return empty string if null is passed as parm. This returns a null. Is this oversight in the Convert method?...
5
by: msnews.microsoft.com | last post by:
How can I convert string to int?
4
by: simon | last post by:
I have datetime variable: DateTime datum; I set it and when I try to put it into a label: labelDate.Text =datum.ToShortDateString; I get an error:
11
by: Newbie! | last post by:
Hi, When i try and build my project which includes a Access Database i get a error saying: `Convert` is not a member of `String` on the following code: Public Sub SetUserNameNull()
6
by: MrKrich | last post by:
I want to convert Hexadecimal or normal integer to Binary. Does VB.Net has function to do that? I only found Hex function that convert normal integer to Hexadecimal.
5
by: moondaddy | last post by:
How do I get the string representation of an int? for example int var1 = 2; string var2 = var1.ToString; I'm wanting var2 to be "2" I get the compile error: Error 1 Cannot convert...
2
by: JEEtoP | last post by:
hoping someone can help, got a bit of homework I'm stuck on. It's as follows... There is a standard class called DateFormat which (among other things) lets you convert dates to various different...
6
by: gator6688 | last post by:
I have to enter a new method (convert() ) to a previous class. this method has to access the month, year and day and return a long integer such as year*10000 + month * 100 + day. I think I did it...
1
by: suhailsiddig | last post by:
these code in vb.net iwant it in c# Sub doUpdate(ByVal source As Object, ByVal e As DataGridCommandEventArgs) ' put the new data back in the datatable Dim objDt As New DataTable()...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.