VB & MSAccess

Discussion in 'Software' started by pallavimahajan, Oct 21, 2004.

  1. pallavimahajan

    pallavimahajan Private E-2

    Hi
    I making a GUI interface for my database in Access. Using Dataenvironment, I have connected my database to the GUI with ODBC. Now i want to add some entries or modify. Can ne1 tell me how addnew command works in this, & how should i approach modifying features.
    Thanks
    Pallavi
     
    Last edited: Oct 21, 2004
  2. Wookie

    Wookie Sergeant Major

    Usually you have a recordset object Heres an example of creating a new record

    Code:
    
    recordset.addnew
    
    recordset.field("myfield") = "Test"
    
    recordset.update
    
    

    Thats about it. Whenever you use addnew it automatically moves the recordset to the new record and then you just set the data in the fields to what you want and use the update command to finish off the write.
     
  3. pallavimahajan

    pallavimahajan Private E-2

    Ok i tried that & it is giving me an error.

    I will post my code here, so incase u find something wrong do tell me

    DataEnvironment1.rsbasic.AddNew
    DatEnvironment.rsbasic.Fields("SEGMENT_ID") = SEGMENT_ID.Text
    DataEnvironment1.rsbasic.Update

    Its giving me error : -2147217887(80040e21)
     
  4. Wookie

    Wookie Sergeant Major


    Edit the database and instead of a text field try making that field a memo
     
  5. Kodo

    Kodo SNATCHSQUATCH

    that would be wasteful if the string he passes is no longer that 255 chars. Find out if the string is a standard size or if it will ever exceed 255 chars. If not, then adjust the text field size to accept more chars.
     
  6. pallavimahajan

    pallavimahajan Private E-2

    I tried modifying my code

    It now gives me runtime error 424, Object required.
     
  7. Kodo

    Kodo SNATCHSQUATCH

    I'd say for what you're doing, either your connection or your recordset object does not exist. Make sure they are created.
     
  8. pallavimahajan

    pallavimahajan Private E-2

    both are created
     
  9. Kodo

    Kodo SNATCHSQUATCH

    are you sure they are still open? test them.

    If isobject(yourobjectnamehere) then
    debug.print "myobject is open)
    else
    debug.print "myobject is closed"
    end if

    do that for your recordset and your connection substituting "yourobjectnamehere" with your connection and recordset object names.
     
  10. pallavimahajan

    pallavimahajan Private E-2

    they are working
     
  11. Kodo

    Kodo SNATCHSQUATCH

    well, some object is being referenced that does not exist. you'll have to find out what it is.
     
  12. pallavimahajan

    pallavimahajan Private E-2

    Can i email u the whole stuff so that u can figure it out
     
  13. Kodo

    Kodo SNATCHSQUATCH

    no,
    post the code here so others can see. I may not be able to get to it ..but maybe someone else will..
     
  14. Wookie

    Wookie Sergeant Major

    copy and paste it, ill take a shot at it tonite, see if I can help you, ill point out errors but im not gonna write the code for you.
     
  15. pallavimahajan

    pallavimahajan Private E-2

    I have made coonection to MS Access databse using Mircrosoft OLEDB provider for ODBC drivers. I can delete & display my data perfectly, but no addition & modification.

    Code:
     
    Private Sub AddCommand1_Click()
    DataEnvironment1.rsbasic.MoveLast
    DataEnvironment1.rsbasic.AddNew
    DatEnvironment1.rsbasic.Fields("SEGMENT_ID").Value = SEGMENT_ID.Text
    DataEnvironment1.rsbasic.Fields("COUNTY").Value = COUNTY.Text
    DataEnvironment1.rsbasic.Fields("RT_NO").Value = RT_NO.Text
    DataEnvironment1.rsbasic.Fields("RT_NAME").Value = RT_NAME.Text
    DataEnvironment1.rsbasic.Fields("SEGMNT_DESCR").Value = SEGMNT_DESCR.Text
    DataEnvironment1.rsbasic.Fields("DIR").Value = DIR.Text
    DataEnvironment1.rsbasic.Fields("LNGTH").Value = LNGTH.Text
    DataEnvironment1.rsbasic.Fields("FUNC_CLASS").Value = FUNC_CLASS.Text
    DataEnvironment1.rsbasic.Fields("MAINT_RD").Value = MAINT_RD.Text
    DataEnvironment1.rsbasic.Fields("NO_LANES").Value = NO_LANES.Text
    DataEnvironment1.rsbasic.Fields("SPD_LIMIT").Value = SPD_LIMIT.Text
    DataEnvironment1.rsbasic.Fields("AVG_SP").Value = AVG_SP.Text
    DataEnvironment1.rsbasic.Fields("CRITICAL_MILES").Value = CRITICAL_MILES.Text
    DataEnvironment1.rsbasic.Update
    Me.Hide
    frmDataEnv.Show
    End Sub
    
     
  16. Wookie

    Wookie Sergeant Major

    WHeres your connection info. Show me the code where you make the data objects and the connection to please.
     
  17. Kodo

    Kodo SNATCHSQUATCH

    this would be so much easier if you use a SQL query for your updates
     
  18. Wookie

    Wookie Sergeant Major

    also have you tried running this in debug mode? It usually points to exactly where the error is and gives you a reason why. From the Fields().value im guessing this is .net
     
  19. pallavimahajan

    pallavimahajan Private E-2

    Connection string

    Provider=MSDASQL.1;Persist Security Info=False;Mode=ReadWrite;Extended Properties="DBQ=C:\Documents and Settings\pallavi\My Documents\Summary_98_03.mdb;DefaultDir=C:\Documents and Settings\pallavi\My Documents;Driver={Microsoft Access Driver (*.mdb)};DriverId=25;FIL=MS Access;FILEDSN=C:\Program Files\Common Files\ODBC\Data Sources\basic.dsn;MaxBufferSize=2048;MaxScanRows=8;PageTimeout=5;SafeTransactions=0;Threads=3;UID=admin;UserCommitSync=Yes;"
     
  20. pallavimahajan

    pallavimahajan Private E-2

    u suggested about SQL query,

    Can u give me a sample?
     
  21. Kodo

    Kodo SNATCHSQUATCH

    I thought that looked familiar..
     
  22. Wookie

    Wookie Sergeant Major

    OK what about where you make the recordset connection and give it SQL and set locking etc.
     
  23. Wookie

    Wookie Sergeant Major


    you started messin with .net yet? I was messin with it at home I got a free copy from my school, havin hell of time using my normal connection methods and I remember seeing the .value in there. but never seen the dataenvironment control. I didnt have the net to look anything up tho.
     
  24. Kodo

    Kodo SNATCHSQUATCH

    I have.. I built a small app already but nothing to do with databases yet. I hate the way .NET works in that respect.
     
  25. Wookie

    Wookie Sergeant Major

    yeah I wasnt to happy, setting a variable = rs.Fields("myfield") kept gicing me errors and I couldnt get any data. I did not figure it out yet, im gonna take another shot at it once I get the net and find some info. Im writing a billing software for myself to keep track of my bills.
     
  26. pallavimahajan

    pallavimahajan Private E-2

    im not messing with .NET, im working in VB 6
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds