home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

Find and Replace in MS Access

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 1565
Discussions: 200,982, Posts: 2,379,845, Members: 246,345
Old May 21st, 2004, 03:02 PM   Digg it!   #1 (permalink)
Senior Member
 
Join Date: Oct 2001
Location: New Hampshire, USA
Posts: 641
Smile
Find and Replace in MS Access

I have been using notepad for quite a while to write/edit UNION and other queries.

The primary reason for using notepad is to take advantage of the FIND/REPLACE utility.

Have any of you ever written a module that would be enable the FIND/REPLACE utility within the SQL VIEW of a query?
ctaylor is offline   Reply With Quote
Old May 24th, 2004, 01:52 AM     #2 (permalink)
Member
 
Join Date: Sep 2002
Posts: 364
I've never heard of it being able to be done. But I guess it depends on the version of Access. Anyways, you can make a form to examine your queries. You can do a find/replace on your form, if you change your find criteria to "Match Any Part of Field." I made a little form to do that. You would want to add error checking/etc if you wanted to use it. You have to reference DAO in the VBA as well. I'll attach the code and pic.




Code:
Option Compare Database
Dim db As Database
Dim qd As QueryDef
Private Sub Form_Load()
    Set db = CurrentDb
    LoadQueries
    Command1_Click
End Sub
Private Sub Form_Unload(Cancel As Integer)
    Set db = Nothing
    Set qd = Nothing
End Sub
Private Sub Combo1_Change()
    If Combo1.SelText = "*NEW*" Then
        Set qd = db.CreateQueryDef(InputBox("Enter a Name"))
    Else
        ShowSQL
    End If
End Sub
Private Sub Command1_Click()
    On Error GoTo cmd1_err
    Text1.SetFocus
    If qd Is Nothing = False Then qd.SQL = Text1.Text
    LoadQueries
cmd1_err:
    If Err.Description <> "" Then MsgBox Err.Description
End Sub
Sub ShowSQL()
    Set qd = Nothing
    Set qd = db.QueryDefs(Combo1.SelText)
    Text1.SetFocus
    Text1.Text = qd.SQL
End Sub
Sub LoadQueries()
    Combo1.SetFocus
    Dim i As Integer
    If Combo1.ListCount > 1 Then
        For i = 0 To Combo1.ListCount - 1
            Combo1.RemoveItem (0)
        Next i
    End If
    Set qd = Nothing
    Combo1.AddItem "*NEW*"
    For Each qd In db.QueryDefs
        Combo1.AddItem qd.Name
    Next
End Sub
Creosote is offline   Reply With Quote
Old May 24th, 2004, 09:58 AM     #3 (permalink)
Senior Member
 
Join Date: Oct 2001
Location: New Hampshire, USA
Posts: 641
Thanks for the code.

Unfortunately it does not working with MS Access 2000 - the AddItem and RemoveItem properties are only available in MS Access 2002 according to one forum post I found, but I'm not sure if this is true...

Perhaps this can be resoplved with another reference? I did find on the MSDN site an Office 2000 article that used this property in a MS Word 2000 mail merge code example though. (http://msdn.microsoft.com/library/de...MergePartI.asp)


Also, I am unable to open the picture you posted. I gather from the code that there is a combo box named combo1, text box called text1, and a command button called command1. Is this all I should need for the form?
ctaylor is offline   Reply With Quote
Old May 24th, 2004, 11:40 AM     #4 (permalink)
Member
 
Join Date: Sep 2002
Posts: 364
Well that sucks about the pic. Here is the link if you want to copy and paste it into your browser:

http://www.end-of-file.com/misc/accessfr3.jpg.

I seriously doubt it is true about the add/remove item. If it is, then it can probably be resolved by reference an Active X control. Do you have VB or Visual Studio installed? You can use some controls from those in Access.
But if that is not possible, there would have to be a way to add items to a combo box programattically in Access 2K IMO.
Creosote is offline   Reply With Quote
Old May 24th, 2004, 12:47 PM     #5 (permalink)
Senior Member
 
Join Date: Oct 2001
Location: New Hampshire, USA
Posts: 641
Thanks for the reply.

I did some more research and found that "In othe rapplications, these controls have AddItem and RemoveItem methods to add and remove items. These methods are not supported for Access list and combo box controls. Instead you use combinations of RowSource and RowSourceType properties to specify the data that appears in a list box or combo box control." Microsoft Office 2000/Visual Basic Programmer's Guide, P. 136.

When looking at examples, I see that a combo box should have its properties set as follows with MS Access 2000

With Me!cboEmployees
.RowSourceType = "Table/Query" 'is a valid line of code
.RowSource = "SELECT EmployeeID, FirstName LastName
FROM Employees
ORDER BY LastName"
.BoundColumn = 1
.ColumnCount = 3
.ColumnWidths = "0in; .5in; .5in"
.ColumnHeads = False
.ListRows = 5
End with

I understand this example well as I have used this kind of language before. Unfortunately I have limited experience with VBA access to DAO. This being the case, would I be correct in thinking that the QueryDefs object is a COLLECTION that contains query names? If so, I think I understand what the LoadQueries procedure is doing, Though I am not fully sure how to re-write the RowSource property in the above example. Perhaps a new recordset object should be created in the LoadQueries procedure that could be assigned to the RowSource Property? What do you think?
ctaylor is offline   Reply With Quote
Old May 24th, 2004, 12:55 PM     #6 (permalink)
Senior Member
 
Join Date: Oct 2001
Location: New Hampshire, USA
Posts: 641
In answer to your earlier question, I do not have Visual Studio installed. I work in the "wrong department" to have access to those kinds of development tools. (I'm an analyst, no longer an IT guy.) Given that limitation, VBA is all that is available to me.
ctaylor is offline   Reply With Quote
Old May 24th, 2004, 10:59 PM     #7 (permalink)
Member
 
Join Date: Sep 2002
Posts: 364
That's why it doesn't work. You have to change .RowSourceType to "Value List". At least in Access 2002, you have to change it, and .AddItem works.
Creosote is offline   Reply With Quote
Old May 25th, 2004, 09:17 AM     #8 (permalink)
Senior Member
 
Join Date: Oct 2001
Location: New Hampshire, USA
Posts: 641
I am able to set the RowSource property of the combo box equal to the following code

.RowSource = "select t.Name from MSysObjects t " & _
"where t.Type = 5 and t.Flags = 0;"

The t.Type = 5 argument selects only queries.

Now the problem is the non-support of the .SQL property in Access 2000. This is an odd problem because both Access 97 and Access 2002 support the property.

This is an issue in the ShowSQL procedure.

I'm very pleased with how close we have gotten to making this work.

Last edited by ctaylor : May 25th, 2004 at 09:23 AM.
ctaylor is offline   Reply With Quote
Old May 25th, 2004, 11:42 AM     #9 (permalink)
Member
 
Join Date: Sep 2002
Posts: 364
Cool. Make sure you are referencing DAO 3.6, or the newest DAO you have. The .SQL property is of the QueryDef object. So what I'm saying is that in case there are other libraries that have QueryDef object, you need to make sure you are using a DAO Query Def object.
Creosote is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads
Thread Thread Starter Forum Replies Last Post
Find and replace jon112981 Applications and Operating Systems 7 July 8th, 2003 12:12 PM
how do you replace a winlogon file in xp? joecls Technical Support 1 June 20th, 2003 08:16 PM
Borland JBuilder Rhino Webmastering and Programming 18 June 7th, 2002 10:11 PM
looking for Pentium II ATX ASUS MB's Sweeper Traders Forum: Buy, Sell, Trade 7 April 25th, 2002 06:05 AM


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Is It Just Me? (3063)
Charges against non-tippers dropped.. (20)
Health Care Rationing (10)
Delete an OS (16)
Nvidia GTX 260 problem (9)
Laptop with wireless problem. (12)
Wireless Televisions. (12)
CPU fan stops spinning randomly (11)
windows vista security holes (18)
Regular Build (11)
Point and Shoot Camera Suggestions. (7)
windows 7 problem (7)
Internet Lost (5)
Multiple Restarts Required at Boot (5)
Recent Discussions
updating BIOS via winflash, claims fi.. (1)
New Server Configuration Suggestions (0)
Desktop Calendar Application (0)
cheap gaming laptop? (12)
Unallocated Space (2)
help me pls laptop just stopped worki.. (1)
C# + LINQ Help (7)
windows vista security holes (18)
[F@H SPAM 11/16/09] ! 1/2 months to r.. (38)
Nvidia GTX 260 problem (9)
Dynex DX E-402 (3)
EVGA 9800 gtx help with finding a goo.. (12)
Multiple Restarts Required at Boot (5)
Point and Shoot Camera Suggestions. (7)
Delete an OS (16)
cell phone won't work (0)
Is the PSU I received dead? (15)
Can't open Word (12)
Steam ID's, Gamertags etc... (4)
Games, Cables, PCI cards, and more fo.. (6)
Dept. of HS: NSA 'Helped' Develop Vis.. (17)
Linksys WMP54GS wireless card problem.. (5)
Help getting around port 80 for camer.. (5)
Skillsoft Network+ Study Software Que.. (10)
Browsers wont load websites (3)


All times are GMT -4. The time now is 02:43 AM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28