Page 1 of 1 1
Topic Options
#115768 - 2004-03-09 07:31 PM Help with updating Access DB!
emw1972 Offline
Fresh Scripter

Registered: 2004-03-09
Posts: 26
Loc: Lincoln, Nebraska
I'm attempting to update an access database with the below script. It doesn't work. I've been working on this thing all day! Can someone help? Below is the code.

I can insert the first record just fine, but my code for the update never gets touched.

On my Access database, the field MAC is a primary key.

Code:
  
$objConn = DBConnOpen('DRIVER={Microsoft Access Driver (*.mdb)}; UID=; PWD=; DBQ=\\ngne-j6-05\test\erictest.mdb')
$recordset = DBGetRecordset($objConn,"SELECT MAC FROM Table1 WHERE MAC='$MACADDR'")
If $recordset.recordcount <> 1
for each $record in $recordset
$=Messagebox("Getting Here!","return code")
$recordsetfields=split($record,chr(10))
for each $field in $recordsetfields
$retcode = DBExecuteSQL($objConn,"UPDATE Table1(DateWritten,TimeWritten,Workstation,IP,Cpu,RAM,OS,ServicePack,IEVER,MSOfficeVer,UserID,FullName) VALUES('$DATEWRITTEN','$TIMEWRITTEN','$WKSTA','$IPADDRESS','$CPUMHZ','$RAM','$VerboseOs','$OSCSDVersion','$IeCurVer','$OfficeCurVer','$UserID','($FullName)')")
next
next
Else
; This means that there is no record in the table that contains this MAC. Insert record now....
$=Messagebox("You are here!!!!","return code")
$retcode = DBExecuteSQL($objConn,"INSERT INTO Table1(DateWritten,TimeWritten,Workstation,IP,MAC,Cpu,RAM,OS,ServicePack,IEVER,MSOfficeVer,UserID,FullName) VALUES('$DATEWRITTEN','$TIMEWRITTEN','$WKSTA','$IPADDRESS','$MACADDR','$CPUMHZ','$RAM','$VerboseOs','$OSCSDVersion','$IeCurVer','$OfficeCurVer','$UserID','($FullName)')")
EndIf


Top
#115769 - 2004-03-09 07:36 PM Re: Help with updating Access DB!
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Where is the WHERE clause in the UPDATE statement?
_________________________
There are two types of vessels, submarines and targets.

Top
#115770 - 2004-03-09 07:41 PM Re: Help with updating Access DB!
emw1972 Offline
Fresh Scripter

Registered: 2004-03-09
Posts: 26
Loc: Lincoln, Nebraska
Ok, I see that I'm missing that. I'll fix that in a minute.

What's the best way to see if my SELECT statement returns anything from my table???

Thanks for the prompt reply!

Eric

Top
#115771 - 2004-03-09 08:25 PM Re: Help with updating Access DB!
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Checking the error code and the contents of the return variable.
_________________________
There are two types of vessels, submarines and targets.

Top
#115772 - 2004-03-09 09:17 PM Re: Help with updating Access DB!
emw1972 Offline
Fresh Scripter

Registered: 2004-03-09
Posts: 26
Loc: Lincoln, Nebraska
You know of an example of checking the contents of a return variable?

I'm having issues with checking for an empty recordset...

Thanks!

Top
#115773 - 2004-03-09 10:19 PM Re: Help with updating Access DB!
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA

If it's empty, it's empty. It depends entirely what type of variable you're checking, string, array, recordset. String would be ='', array would be checked via UBOUND and in case of a record set it's recordset.BOF=recordset.EOF or recordset.COUNT=0.


Edited by sealeopard (2004-03-09 10:30 PM)
_________________________
There are two types of vessels, submarines and targets.

Top
#115774 - 2004-03-10 01:05 PM Re: Help with updating Access DB!
emw1972 Offline
Fresh Scripter

Registered: 2004-03-09
Posts: 26
Loc: Lincoln, Nebraska
Thanks for your post! I greatly appreciate your assistance.

I guess I'm used to VB and how it prompts you for available options, if any were available, after I would type in "recordset." Like recordset.count, recordset.eof, etc, etc.

I'm working with Kixtart in notepad. Is another tool available? As you can obviously tell, I'm new to this.

I do have a few more code questions though...

With the below code, if my Access DB is empty, it will insert a record.

On the next run of this code (when I logoff/logon) I get a Scriptlogic error message about the execution of this script.

I don't understand why it doesn't work. If the recordset is not empty, I would expect it to go to the ELSE statement and send me a messagebox. Do I need to do some sort of other check?

Code:
  
$objConn = DBConnOpen('DRIVER={Microsoft Access Driver (*.mdb)}; UID=; PWD=; DBQ=\\ngne-j6-05\test\erictest.mdb')
$recordset = DBGetRecordset($objConn,"SELECT MAC FROM Table1 WHERE MAC='$MACADDR'")
$=Messagebox("TEST 1"," ")
If $recordset=''
; This means that there is no record in the table that contains this MAC. Insert record now....
$=Messagebox("TEST 2"," ")
$retcode = DBExecuteSQL($objConn,"INSERT INTO Table1(DateWritten,TimeWritten,Workstation,IP,MAC,Cpu,RAM,OS,ServicePack,IEVER,MSOfficeVer,UserID,FullName) VALUES('$DATEWRITTEN','$TIMEWRITTEN','$WKSTA','$IPADDRESS','$MACADDR','$CPUMHZ','$RAM','$VerboseOs','$OSCSDVersion','$IeCurVer','$OfficeCurVer','$UserID','($FullName)')")
Else
$=Messagebox("TEST 3"," ")
EndIf
$retcode = DBConnClose($objConn)




Top
#115775 - 2004-03-10 03:27 PM Re: Help with updating Access DB!
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Please read the FAQ Forum, e.g. Can't decide what editor to use... Maybe this'll help

You might also want to use the DBCommand() UDF instead as it is easier to use. The DBGetRecordSet() returns a recordset object, not a string variable. You will thus have to check whether the recordset object is empty or not.

You should also read the kiXtart Manual under DEBUG as well as the debugging section.
_________________________
There are two types of vessels, submarines and targets.

Top
#115776 - 2004-03-13 02:30 PM Re: Help with updating Access DB!
Chaguito Offline
Getting the hang of it

Registered: 2002-05-17
Posts: 53
Quote:

I'm attempting to update an access database with the below script. It doesn't work. I've been working on this thing all day! Can someone help? Below is the code.

I can insert the first record just fine, but my code for the update never gets touched.

On my Access database, the field MAC is a primary key.

Code:
  
$objConn = DBConnOpen('DRIVER={Microsoft Access Driver (*.mdb)}; UID=; PWD=; DBQ=\\ngne-j6-05\test\erictest.mdb')
$recordset = DBGetRecordset($objConn,"SELECT MAC FROM Table1 WHERE MAC='$MACADDR'")
If $recordset.recordcount <> 1
for each $record in $recordset
$=Messagebox("Getting Here!","return code")
$recordsetfields=split($record,chr(10))
for each $field in $recordsetfields
$retcode = DBExecuteSQL($objConn,"UPDATE Table1(DateWritten,TimeWritten,Workstation,IP,Cpu,RAM,OS,ServicePack,IEVER,MSOfficeVer,UserID,FullName) VALUES('$DATEWRITTEN','$TIMEWRITTEN','$WKSTA','$IPADDRESS','$CPUMHZ','$RAM','$VerboseOs','$OSCSDVersion','$IeCurVer','$OfficeCurVer','$UserID','($FullName)')")
next
next
Else
; This means that there is no record in the table that contains this MAC. Insert record now....
$=Messagebox("You are here!!!!","return code")
$retcode = DBExecuteSQL($objConn,"INSERT INTO Table1(DateWritten,TimeWritten,Workstation,IP,MAC,Cpu,RAM,OS,ServicePack,IEVER,MSOfficeVer,UserID,FullName) VALUES('$DATEWRITTEN','$TIMEWRITTEN','$WKSTA','$IPADDRESS','$MACADDR','$CPUMHZ','$RAM','$VerboseOs','$OSCSDVersion','$IeCurVer','$OfficeCurVer','$UserID','($FullName)')")
EndIf






Instead of using

If $recordset=''

use

IF UBOUND($recordset)=-1

This means that if recordset is empty. I tried it the same way you did and most of the times gave me errors.
_________________________
Chaguito, MCP

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 867 anonymous users online.
Newest Members
JimDunn, fgarcia, Viginette, ManuvdWielNL, Sir_Barrington
17890 Registered Users

Generated in 0.058 seconds in which 0.024 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org