Code/macro to do auto replace

elliotth123

Registered User.
Local time
Today, 15:31
Joined
Sep 21, 2004
Messages
28
I am looking for a way of creating the following:
I want to be able to click a command button and have it prompt the user for input.
Then take the input and replace all cases of NA with that string in field B for all records.
I would prefer to have no other prompts other that the user input and a success msg box.
Can this be done?
 
Yes, several ways. But how comfortable are you with VBA?

Basically, I would build the button using a button wizard. An option exists for you to run SQL using this wizard. Let it build that code, but then you are going to go back in and edit the code it built for you. You might have to create a dummy update query that updates the right field for some dummy value, say, XYZ, in quotes, and your criteria string of NA must also be part of that query. Use the query grid (design view) to create the query. For TWO reasons, you would want this query to exist.

OK, now you have button event code to run a query. But... that code will reference the dummy query. Look up the action that it built for you, probably either RunSQL or Execute or something like that. The Help Files will tell you how to supply a STRING instead of a stored query.

Now before the DoCmd that runs your query, you have to do a few things.

First, using an InputBox, capture your required data.

Second, build a string containing the desired Update SQL information. Look at the dummy Update query in SQL view to see what this looks like. In this string, you will have an UPDATE verb and some field names and the WHERE clause that contains your criterion "WHERE field-name = ""NA"";"

OK, where it contains the constant "XYZ" in quotes, you will build the string

mysqlstring = "UPDATE table-name ..... " and put the field contents in via concatenation.

That should do it for you if you get the quotes right.
 
Hmm

Well I sort of understand that....
I am fairly new to VBA...

Let me rephrase what I am trying to do maybe you can think of a better way than what I said.

I am importing a excel file with book information into a table. Around 150 at a time. I want to be able to easily say fill in the location field for each book to a certain shelf number. Does this make sense?
This in the end is being used as a resource library program for my fiance school system. I am just trying to find a way to automate some functions. Any idead i would appreciate it.
Thanks!
 

Users who are viewing this thread

Back
Top Bottom