ADODB ACCESS MDB Problem

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
bsharp
Newbie
Posts: 16
Joined: Tue Nov 29, 2005 6:39 am
Location: New York

ADODB ACCESS MDB Problem

Post by bsharp » Tue Nov 29, 2005 7:32 am

I am working on a script for a program that uses an access database. The MDB table I am working with consists of 1 row and 200 columns every 8 columns consists of a relative group. I successfully imported the data using a delimited string and than used separate to import them. Hence I only needed 25 separate functions to import the data. I then collated the data and built a dialog box to manipulate it with. Now I have to set the data back to the MDB. But I can’t seem to be able to set the table field up as a variable. It would be very helpful if I could do this as writing 200 separate VB functions for each import would be crazy.


This is my test script;

VBSTART
Sub ChangePROG(SIQ,NewPROG)

set MyDB = CreateObject("ADODB.Connection")
MyDB.Open "FMS"
MyDB.Execute = "Update SCHE Set SIQ = ('" & NewPROG & "')"
MyDB.Close

End Sub
VBEND
LET>SIQ=
LET>SIQCNT=0
LET>PROGRAM_SIQ=PROGRAM_SIQ%CRLF%
LABEL>MODLOOP
ADD>SIQCNT,1
LET>SIQ=PROGRAM_SIQ%SIQCNT%
Input>NewPROG,Enter New PROG:,TEST
VBRun>ChangePROG,SIQ,NewPROG
Goto>MODLOOP


If I change SIQ in the VB to PROGRAM_SIQ1 it will work but I need it to pass a variable.
I am sure there must be a simple way of doing it.

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Nov 29, 2005 8:28 am

Hi,

SIQ is a literal in your SQL string:

MyDB.Execute = "Update SCHE Set SIQ = ('" & NewPROG & "')"

I think you mean:

MyDB.Execute = "Update SCHE Set " & SIQ & " = ('" & NewPROG & "')"

However, I notice that you have embedded a CRLF (carriage return and line feed) character pair in the variable. This is likely to cause errors since I doubt SQL particularly likes field names with line breaks in them.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

bsharp
Newbie
Posts: 16
Joined: Tue Nov 29, 2005 6:39 am
Location: New York

Post by bsharp » Wed Nov 30, 2005 12:35 am

Thank You it works like a charm. I had thought I had tried that but I must have missed some thing. I knew there was a simple way.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts