Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ VBscript
➜ someone help im about to kill myself - Yet more Databases and Active X
|
someone help im about to kill myself - Yet more Databases and Active X
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Ishnaf
Australia (17 posts) Bio
|
| Date
| Tue 01 Oct 2002 02:14 PM (UTC) |
| Message
| Why wont this work? Im dying over here :P
This is supposed to add info (which i am getting okay from mushclient) to a database. It doesnt. Can someone plllllleeeeaaaaassssseeeeeee tell me why......
Sub GetStuff(gworld As World)
dim item, iteminfo, 'etc... i dim everything
'i have lots of getvariables here usually - you dont need to see this its working fine :)
'the next bit wont work :|
'~~~ADD INFO INTO THE DATABASE~~~'
'this is supposed to open ITEMDB recordset:
Dim Itemdb As Database
Dim RecSet As Recordset
'okay, the db below (newdatabase.mdb) has a table called "items"
'im attempting to open it :)
Set itemdb = OpenDatabase("C:\Program Files\MUSHclient\ishnaf\DBproject\newdatabase.mdb")
Set RecSet = itemdb.OpenRecordset("Items", dbOpenDynaset)
'now im trying to add a record to this record source
With RecSet
'Set it to Add mode
.AddNew
.Fields("Item").Value = Item
.Fields("ItemType").Value = itemtype
.Fields("ItemIs").Value = itemis
.Fields("ForgeLevel").Value = forgelvl
.Fields("DiceNo").Value = diceno
.Fields("DiceSize").Value = dicesize
.Fields("Weight").Value = weight
.Fields("Value").Value = valuee
.Fields("Rent").Value = rent
.Fields("ACApply").Value = acapply
.Fields("Armor").Value = Armor
.Fields("CON").Value = con
.Fields("INTEL").Value = intel
.Fields("WIS").Value = wis
.Fields("DEX").Value = dex
.Fields("CHA").Value = Cha
.Fields("STR").Value = stre
.Fields("Hitroll").Value = hitroll
.Fields("Damroll").Value = damroll
.Fields("maxhit").Value = maxhit
.Fields("maxmana").Value = maxmana
.Fields("Uselevel").Value = uselevel
.Fields("Age").Value = age
'Update it
.Update
'Close it
.Close
End With
Set db = Nothing
'to send something to world to see if the script makes it to here
gworld.Note "The Item Has been added. Perhaps :P"
End Sub
Any ideas? Or am i insane? |
egads! | | Top |
|
| Posted by
| Shadowfyr
USA (1,792 posts) Bio
|
| Date
| Reply #1 on Tue 01 Oct 2002 06:46 PM (UTC) |
| Message
| With RecSet
'Set it to Add mode
.AddNew
.Fields("Item").Value = Item
...
You sure this works? Seems to me that you need to .AddNew before you do anything 'With' it. i.e.
RecSet.AddNew
With RecSet
.Fields("Item").Value = Item
...
It would seem to me that you can't set the fields to an empty record set, so until you do AddNew, there are no fields to put anything into. In most cases stuff like AddNew don't define a mode, but create a new record or object. However that is only a 'major' guess. | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #2 on Thu 03 Oct 2002 01:07 PM (UTC) |
| Message
|
Quote:
Seems to me that you need to .AddNew before you do anything 'With' it.
With is just a VB shortcut, at compile time. It has nothing to do with executing the code. eg.
x.AddNew
and
With x
.AddNew
End With
are identical. However using "with" in a long sequence (as above) saves typing the object name repetitively on each line.
As for why the code doesn't work, I'll try it tomorrow. In what way doesn't it? An error message? No record inserted?
Personally I would use "INSERT INTO table blah blah" rather than the recordset approach, and then do db.Execute on that SQL statement.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Ishnaf
Australia (17 posts) Bio
|
| Date
| Reply #3 on Thu 03 Oct 2002 04:13 PM (UTC) |
| Message
| The error is "type mismatch" *boggle*
Have fun :P |
egads! | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #4 on Thu 03 Oct 2002 10:30 PM (UTC) |
| Message
| After quite a bit of mucking around, I did not get the "addnew" approach to work. However the direct execution of SQL seems to work fine, so I suggest using this, rather than killing yourself. :)
dim db
Set db = CreateObject ("ADODB.Connection")
db.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=z:\test.mdb"
db.Execute "INSERT INTO itemtable VALUES (0, ""a"", ""b"", 5, 6);"
set db = nothing
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
18,336 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top