GlockTalk.com
Home Forums Classifieds Blogs Today's Posts Search Social Groups



  
SIGN-UP
Notices

Glock Talk
Welcome To The Glock Talk Forums.
Reply
 
Thread Tools Display Modes
Old 06-18-2004, 12:19   #1
gudel
Senior Member
 
gudel's Avatar
 
Join Date: Jun 2001
Posts: 4,047
vbs coder

are there any vbscript guys here? i need some pointers on how to read/write access mdb/SQL stuff.
i searched google, but mostly it's for ASP.
gudel is offline   Reply With Quote
Old 06-18-2004, 13:03   #2
Blazen
B-Lazy
 
Blazen's Avatar
 
Join Date: Oct 2001
Location: Texas
Posts: 210
Send a message via MSN to Blazen
This may or may not help you out...

http://cwashington.netreach.net/depo...tType=vbscript

Its a nice site that has loades of "scripting" examples/solutions...

;c
__________________
Sub Club #9999
Top Guns 357 Sig Club #9999
.40 S&W Club #9997
The Niner's Club #9997
TT #9999
Lone Star Glockers #9999
Blazen is offline   Reply With Quote
Old 06-18-2004, 13:04   #3
Blazen
B-Lazy
 
Blazen's Avatar
 
Join Date: Oct 2001
Location: Texas
Posts: 210
Send a message via MSN to Blazen
Also from my understading...ASP and VBscript play hand and hand...so things should work the same; might be a slight change in coding.
__________________
Sub Club #9999
Top Guns 357 Sig Club #9999
.40 S&W Club #9997
The Niner's Club #9997
TT #9999
Lone Star Glockers #9999
Blazen is offline   Reply With Quote
Old 06-21-2004, 08:33   #4
Darkmage
Senior Member
 
Darkmage's Avatar
 
Join Date: Mar 2001
Location: Purgatory, Virginia
Posts: 1,176


What environment are you using? Word macros, compiled VB, MS Access application or ASPs?
__________________
"If there are guns in the house, one had better be yours."
--------------
Tech Forum #42
Glockers of the Old Dominion #42
Darkmage is offline   Reply With Quote
Old 06-21-2004, 10:13   #5
gudel
Senior Member
 
gudel's Avatar
 
Join Date: Jun 2001
Posts: 4,047
simply vbs script from xp to read/write Access' mdb.
i found a sample code for ado, will have to try it to see if it works.
gudel is offline   Reply With Quote
Old 06-25-2004, 11:03   #6
Darkmage
Senior Member
 
Darkmage's Avatar
 
Join Date: Mar 2001
Location: Purgatory, Virginia
Posts: 1,176


That shouldn't be too hard. I have lots of experience with the ADO code, so let me know if you need a hand.
__________________
"If there are guns in the house, one had better be yours."
--------------
Tech Forum #42
Glockers of the Old Dominion #42
Darkmage is offline   Reply With Quote
Old 07-01-2004, 14:49   #7
gudel
Senior Member
 
gudel's Avatar
 
Join Date: Jun 2001
Posts: 4,047
okay, i have an MS Access .mdb file. I need to read/write to the record/field.

I got this part

Code:
'* i make connection here 
SET CONN = CreateObject("ADODB.Connection")

'* this i don't understand, what do i do here to link to a straight .mdb file 
Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & "c:\filename.mdb"

'* i think i'm gonna need this for write 
Set RS = CreateObject("ADODB.Recordset")
I was wondering if anyone has something like this, basically it sets up the necessary code to open/read/write an .mdb Access file. Nothing fancy like opening up a query/relational or moving records etc, just the basic open/read/write/close.
gudel is offline   Reply With Quote
Old 07-01-2004, 15:12   #8
gudel
Senior Member
 
gudel's Avatar
 
Join Date: Jun 2001
Posts: 4,047
looks like i'm on to something here, found this page
http://msdn.microsoft.com/library/de...invbscript.asp

i guess i'll just have to try them out!
gudel is offline   Reply With Quote
Old 07-02-2004, 20:53   #9
Darkmage
Senior Member
 
Darkmage's Avatar
 
Join Date: Mar 2001
Location: Purgatory, Virginia
Posts: 1,176


It looks like you're well on your way. However, the line that starts with "OPEN" isn't going to work. You didn't specify what is going to attempt to open. It should probably read:
sSQLCONN.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\filename.mdb"

In the abstract, what you are doing in the first line is defining an ADO connection object. The recordset you create in the third line will be your interface to the actual data and the recordset will use the connection object when it wonders where to go fetch.

The second line with all the gobbledygook is where you tell the connection object to establish a connection with your MS Access file. When you're done executing commands against your database, remember to close your connection object like so:
CONN.close

Now that you have an open connection and a recordset, you should now open the recordset. In order to do that you have to 1) give it a SQL query to work with and 2) tell it to use the CONN object.
RS.Open "SELECT * FROM Table1", CONN

Your code to read from "Table1" goes here.

And at last, clean up a bit.

RS.close
SET RS = Nothing
CONN.close
SET CONN = Nothing
__________________
"If there are guns in the house, one had better be yours."
--------------
Tech Forum #42
Glockers of the Old Dominion #42
Darkmage is offline   Reply With Quote
Old 07-03-2004, 01:58   #10
gudel
Senior Member
 
gudel's Avatar
 
Join Date: Jun 2001
Posts: 4,047
thanks

yeah that Open looks weird, forgot to put the object there

RS.Open "SELECT * FROM Table1", CONN
This is the part that I often confused on the Table1 label, that line looks straight forward.

hopefully my access kungfu will be better after this ;f
gudel is offline   Reply With Quote
Old 07-06-2004, 22:37   #11
Darkmage
Senior Member
 
Darkmage's Avatar
 
Join Date: Mar 2001
Location: Purgatory, Virginia
Posts: 1,176


When you can query the recordset from my hand, grasshopper...
__________________
"If there are guns in the house, one had better be yours."
--------------
Tech Forum #42
Glockers of the Old Dominion #42
Darkmage is offline   Reply With Quote
Old 08-31-2004, 00:33   #12
gudel
Senior Member
 
gudel's Avatar
 
Join Date: Jun 2001
Posts: 4,047
Darkmage, perhaps you can figure this out.
I'm trying to retrieve a value from a field. it's a phone number. in access table, it shows as 800-555-1212. but when I use vbs to grab
it, all i got is 8005551212
say I put it like:
WScript.Echo objRecordset.Fields.Item("Telephone")
I could separate these using Left,Mid and Right, but that's more code Not sure if it's possible to format it, or am I just stuck with it?
gudel is offline   Reply With Quote
Old 08-31-2004, 08:36   #13
Darkmage
Senior Member
 
Darkmage's Avatar
 
Join Date: Mar 2001
Location: Purgatory, Virginia
Posts: 1,176


The data is actually stored as a string value, as "8005551212". Access is formatting that number to make it appear like a regular phone number.

There is a Format function in VBA, but you need to use a user-defined format. There is no "phone number" format.

Try this:

sMyString = Format(objRecordset.Fields.Item("Telephone"), "@@@-@@@-@@@@")

or

sMyString = Format(objRecordset.Fields.Item("Telephone"), "&&&-&&&-&&&&")
__________________
"If there are guns in the house, one had better be yours."
--------------
Tech Forum #42
Glockers of the Old Dominion #42
Darkmage is offline   Reply With Quote
Old 08-31-2004, 11:31   #14
gudel
Senior Member
 
gudel's Avatar
 
Join Date: Jun 2001
Posts: 4,047
it didn't work, it would've work if it's run in office apps, but i run it from script. there's no format function in in wsh/vbs for this particular kind. but that's okay, the alternative seems to work though.
gudel is offline   Reply With Quote
Old 09-01-2004, 12:39   #15
Darkmage
Senior Member
 
Darkmage's Avatar
 
Join Date: Mar 2001
Location: Purgatory, Virginia
Posts: 1,176


Whoops! I forgot you were building an ASP. I've been fighting VB code for the past two weeks and I've got it on the brain.

I guess it will go like this then:

Dim sPhoneString
sPhoneString = objRecordset.Fields.Item("Telephone")
sPhoneString = mid(sPhoneString, 1, 3) & "-" & mid(sPhoneString, 4, 6) & "-" & mid(sPhoneString, 7, 10)


Just a little unnecessary hint: instead of trying to get everything done in one line (multiple mid statements on the full objRecordset.Fields("Telephone") thing), the above code only makes one call of the recordset object, handling the rest in VBScript code. This will save you two round-trips to the recordset object to get the value.

Granted, this is only a concern in large queries and high-traffic web sites. But it's the thought that counts.
__________________
"If there are guns in the house, one had better be yours."
--------------
Tech Forum #42
Glockers of the Old Dominion #42
Darkmage is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump




All times are GMT -6. The time now is 01:37.



Homepage
FAQ
Forums
Calendar
Advertise
Gallery
GT Wiki
GT Blogs
Social Groups
Classifieds


Users Currently Online: 788
182 Members
606 Guests

Most users ever online: 2,244
Nov 11, 2013 at 11:42