change a sql on the fly. Can it be done?

Lorddrago
11-06-2004, 11:46 AM
Is there a way that I can have my program change the zzz in the below script to something I inport from a text file with.

Imports script


Open App.Path & "\t1.txt" For Input As #1
Line Input #1, strText
t600.Text = strText
Close #1


Part that needs to be changed


Set rs = New ADODB.Recordset
rs.Open "SELECT * FROM zzzzz", Conn, adOpenStatic, adLockOptimistic

What I want is when I compile the program for some friends I whant each of them to be getting data from a diffrent field and not have to go back in and hard code each part every time. It would be easer to just change the text file and send it with the program.

MKoslof
11-06-2004, 12:07 PM
You can pass in a variable for your table name..remember this is just a string. But you need to send this parameter at runtime. Basically you need to write a function that takes a string parameter and send the table name as a string at runtime.

Lorddrago
11-06-2004, 12:13 PM
You can pass in a variable for your table name..remember this is just a string. But you need to send this parameter at runtime. Basically you need to write a function that takes a string parameter and send the table name as a string at runtime.

This is what I am working on right now to see if I can get this to work the right way. It does not look right to me thoe.

Form Load

Open App.Path & "\meet.txt" For Input As #1
Line Input #1, strText
meet.Text = strText
Close #1


Commandbutton1_click

Set rs = New ADODB.Recordset
rs.Open "SELECT * FROM commandl", Conn, adOpenStatic, adLockOptimistic
Meeting = rs.Fields("m" & meet).Value

My thought is that I have an invisable text box called meet.text and bring the information in with the app.path on start up then hopefully have it placed in the string above?

Am I heading in the right direction on this?

MKoslof
11-06-2004, 03:14 PM
No, that's not going to work. This is your sql statement:

SELECT * FROM Command1

This assumes Command1 is a table object within your Conn database conection, if not, this will fail. If this is true, you can't assign your Meeting variable to a "guessed" field value. Meeting needs to be assigned to a field value that is returned from this open statement.

If you want to return random fields and records, you should be randomizing your query, so it always returns different records. If you do a search of this forum for Randomize or Rnd() you will get a bunch of hits.

Lorddrago
11-07-2004, 08:43 AM
no I don't whant a random field at all. The idea is that the text coming in from the text doc. will point to the table and field I want the information to come from.

Starting to feel very lost on this.

Lets see if I can explain this more. Its a hard concept to type out. The program starts and loads a TXT file from the harddrive called meeting.txt then there is a button that you can push and it will go to a desinated table on a remote mysql. The meeting.TXT needs to be able to tell the sql string what field to get the information from and it has to be exact. So lets say in the meeting.txt it has hsboonstra. That would tell the sql to:

cn1 = rs.Fields("???").Value <---The ??? needs to equal meeting.txt in this case it would be hsboonstra.


lets say that on another version I give to another friend I have in the meeting.TXT file the word rdthomas, now that would tell the program to go to the same table and retreave the field like:
[code]
cn1 = rs.Fields("???").Value <---The ??? needs to equal meeting.txt in this case it would be rdthomas.
The table will always stay the same it is just the fields I need to change with a text file.
Hope this makes more sence on what I am trying to do because it is just about time to go on a drinking venge until I either see the lite of my mistake or I pass out and forget about this little project. LOL hope somone can see how to do this.

Thanks Robert

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum