Datagrid, Saving And Updating To Access Database
Hello
I am using a datagrid and l would like to update and save the contents to the access database. The customer would like to have an excel style grid, that they can navigate and edit details to it, then update. And also they like to be able to add a new record and add that to the database.
I am using the data environment, as l needed to print some reports (working ok)
Code so far.
Code:'updating deCustomers.rsCmdCustomers.update
'saving deCustomers.rsCmdCustomers.save
Many thanks in advance
Steve
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Datagrid Saving To A Access Database
Hello
I am using a datagrid and l would like to update and save the contents to the access database. The customer would like to have an excel style grid, that they can navigate and edit details to it, then update. And also they like to be able to add a new record and add that to the database.
I am using the data environment, as l needed to print some reports (working ok)
Code so far.
Code:
'updating
deCustomers.rsCmdCustomers.update
'saving
deCustomers.rsCmdCustomers.save
Many thanks in advance
Steve
Updating Database And Saving
Hi guys,
at the moment my code allows me to view specific orders from my 'order' table and lets me update to say an order has been completed when i tick the 'completed' checkbox. I also have code to subtract the 'received' number from the 'quantity' number and show result in outstanding, but cant get this to save in the selected record and update the 'quantity' in my 'currentstock' table. Example: if there are 2 laptops ordered and only 1 comes in, when updated it needs to add 1 to 'quantity' in 'currentstock' table in the database. Here is my code at the moment:
Code:
Option Explicit
'declaring the number of records for the reposition'
Dim IngNosRecords As Long
Dim OrderMsgBox As Integer
Dim Sum As Long
Private Sub cmdBack_Click()
Unload Me
selection.Show
End Sub
Private Sub Form_Activate()
'record view'
With datOrder.Recordset
.MoveLast
IngNosRecords = .RecordCount
.MoveFirst
End With
End Sub
Private Sub datOrder_Reposition()
'Shows in the lable what record is being viewed out of how many records are there'
With datOrder.Recordset
lblCurrentRecord.Caption = "Order: " & ((.AbsolutePosition) + 1) & "of" & IngNosRecords
End With
End Sub
Private Sub Form_Load()
'Opens the DB'
datOrder.DatabaseName = App.Path & IIf(Right$(App.Path, 1) <> "", "", "") & "Audit1.mdb"
'SQL command to view only orders that are not completed'
datOrder.RecordSource = "SELECT * FROM [Order] WHERE Order.Completed = 0 ORDER BY Order.ReqNo"
End Sub
'Buttons to move through the records'
Private Sub cmdNext_Click()
datOrder.Recordset.MoveNext
If datOrder.Recordset.EOF Then
datOrder.Recordset.MoveLast
End If
End Sub
'Buttons to move through the records'
Private Sub cmdPrevious_Click()
datOrder.Recordset.MovePrevious
If datOrder.Recordset.BOF Then
datOrder.Recordset.MoveFirst
End If
End Sub
'Buttons to move through the records'
Private Sub cmdFirst_Click()
datOrder.Recordset.MoveFirst
If datOrder.Recordset.EOF Then
datOrder.Recordset.MoveFirst
End If
End Sub
'Buttons to move through the records'
Private Sub cmdLast_Click()
datOrder.Recordset.MoveLast
If datOrder.Recordset.BOF Then
datOrder.Recordset.MoveLast
End If
End Sub
Private Sub cmdUpdate_Click()
'When button is clicked, it will check input from check box and msgbox then update'
OrderMsgBox = MsgBox("Please confirm that this order has been completed", vbExclamation + vbYesNo)
If Check1.Value = 1 And OrderMsgBox = 6 Then
UpdateCompleted
Unload Me
UpdateStock1.Show
Else
Sum = CLng(txtQuantity.Text) - CLng(txtReceived.Text)
txtOutstanding.Text = CStr(Sum)
SumSave
End If
End Sub
Private Function UpdateCompleted()
'With condition to edit and update the completed field in the order table'
With datOrder.Recordset
.Edit
.Fields("Completed") = Check1.Value
.Update
End With
End Function
Private Function SumSave()
With datSum.Recordset
.Edit
.Fields("Outstanding") = txtOutstanding
.Update
End With
End Function
Updating Database From Datagrid Help
Hi All,
Im currently learning vb.net but am having trouble updating records from a datagrid into a dataset and then into the database. I've studdied many books with this problem and i think im getting into a muddle between all the possible solutions. when daStockControl.Update(dsStockControl, "Stock") is called the following error appears "the UpdateCommand affected 0 records."
It seems that cmdUpdate.CommandText = "UPDATE Optim SET Serial_No = @Serial_No WHERE Eq_Number = @Eq_Number" is the problem line as the problem as @Serial_No doesnt map to the datagrid and no data is collected.
Code:
Imports System.Data.OleDb
Module modConnection
Public dtStockControl As New DataTable()
Public daStockControl As New OleDb.OleDbDataAdapter()
Public dsStockControl As New DataSet()
Public connStockControl As New OleDb.OleDbConnection()
Public Sub DatabaseConnection()
Dim strConnectString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & System.Windows.Forms.Application.StartupPath & "stock control.mdb;Persist Security Info=False"
Dim strStockControl As String = "SELECT * FROM Optim"
connStockControl.ConnectionString = strConnectString
daStockControl.SelectCommand = New OleDb.OleDbCommand(strStockControl, connStockControl)
daStockControl.Fill(dsStockControl, "Stock")
dtStockControl = dsStockControl.Tables("Stock")
End Sub
End Module
Code:
Private Sub frmStockControl_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Load datbase connection details.
Call DatabaseConnection()
grdStockControl.DataSource = dsStockControl
'Bind data to data grid
grdStockControl.SetDataBinding(dsStockControl, "Stock")
'dsStockControl.Relations.Add("Stock", dsStockControl.Tables("Optim"))
Dim i As Object
End Sub
Private Sub ErrorHandler() 'Displays catched error within program
MsgBox("ERROR DETECTED WITHIN PROGRAM. PLEASE NOTE DOWN DETAILS." & vbCrLf & vbCrLf & "Error Number: " & Err.Number & _
vbCrLf & "Description: " & Err.Description & vbCrLf & "Source: " & Err.Source, MsgBoxStyle.Critical)
End Sub
Private Sub grdStockControl_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles grdStockControl.CurrentCellChanged
'If the datagrid has been updated then update the recordset
If dsStockControl.HasChanges = True Then
MsgBox("Database Updated = " & dsStockControl.HasChanges, MsgBoxStyle.Information, "Done")
Try
daStockControl.MissingSchemaAction = MissingSchemaAction.AddWithKey
Dim cmdUpdate As New OleDb.OleDbCommand()
Dim prm As OleDb.OleDbParameter
cmdUpdate.Connection = connStockControl
cmdUpdate = connStockControl.CreateCommand
cmdUpdate.CommandText = "UPDATE Optim SET Serial_No = @Serial_No WHERE Eq_Number = @Eq_Number"
'MsgBox(dsStockControl.GetUpdateCommand.CommandText.ToString)
prm = cmdUpdate.Parameters.Add("@Eq_Number", OleDb.OleDbType.Integer, 255, "Eq_Number")
prm = cmdUpdate.Parameters.Add("@Serial_No", OleDb.OleDbType.VarChar, 255, "Serial_No")
daStockControl.UpdateCommand = cmdUpdate
daStockControl.Update(dsStockControl, "Stock")
Catch ex As Exception 'Catch and display any errors
MsgBox("Error: " & ex.Source & ": " & ex.Message, MsgBoxStyle.OKOnly, "Database Error")
Console.Write(ex.Message)
End Try
End If
End Sub
End Class
Thanks for any help in advance.
Updating 2tables In Database Based On New Record In Datagrid
in my datagrid i have allowed for updates. the datagrid is bound to an adodc, whose datasource is a SQL statement (ie not a table in the access database). the datagrid contains 3 columns - 2 from the products table in the database and 1 from a related price table. how do i reference these 3 fields (for an insert SQL statement) when adding and saving a new record (row) in the datagrid? if you need any additional information, please let me know! any help would be greatly appreciated!
Updating MS Access Table With ADO Data Control From A Datagrid
Hi,
I'm populating a datagrid with the data of a MS access table using ADO Data Control. If I change the datagrid values, its automatically updating the table contents. Is there any property of the ADO data control, so that only on setting that value, the data grid changes should be reflected in the DB & not otherwise.
regards,
narayan
Saving Datagrid To Access
I am new to VB and having a problem saving my information in the datagrid into an access file or even a text file.
It will save it to excel but it only saves the first record. Can anyone help me with this problem?
Below is the code I have so far for the save feature:
rivate Sub cmdSave_Click()
Dim grdData As String
Dim iFile1 As Integer
iFile1 = FreeFile 'open the file for writing
Open "C:Dataout.csv" For Output As #iFile1
Write #iFile1, " Column1 "
Write #iFile1, " Column2 "
Write #iFile1, " Column3 "
Write #iFile1, " Column4 "
Write #iFile1, " Column5 "
Close #iFile1
End Sub
Saving From Datagrid To Access
Hi all
Anybody know how to save what the user changes in a datagrid (on a form) back in the Access .mdb file? Do i need to use a common dialog box or does the datagrid have a special property/command for that?
Thanx
- stacey xx
Updating An Access Database In Vb6
I have a database named acesar.mdb with many tables one of which is called "userfile". Within that table is a field called "expDate" which is a date field in date/time format. I want to have a routine which adds one year to each record (member) of that table for that field. Can someone help me with this? The event will be triggered by a "special" password which I have already done. Thanks.
Updating An ACCESS 97 DataBase...
Hi !!
Here's the problem...
I've got a project running with a Access97 DB and I'd like to upgrade it regularely from a *.txt file... is it possible ? and do I have to convert the *.txt into Access (*.mdb) first ?
I'm lost... How can I do ?
Thank you
COSIDUS
Updating Access Database
Hi
Making the conversion from VB6 to VB.NET has been extremely difficult for me. Everytime I think that I have things working right, something else appears. Here's the latest.
My code to update a database is (I thought) very simple as shown here
dataAdapter.Update(dataSet,"Table")
Unfortunately, this results in an error message that reads "Update requires a valid UpdateCommand when passed a DataRow collection with modified rows."
I have tried to find this message in Microsoft's KB and in the help files but can't and hove no clue as to the cause. My code is identical to the code in the tutorial I am working with.
Can anyone help a very frustrated novice?
Updating Access Database Using VB6
Hi,
I have a quite confusing question. I am writing a Visual Basic 6.0 program that interacts with two databases. One is an existing database created by someone else. This database has Access forms for the user to fill out. One of the fields on these forms is a lookup text field. In my program, I am trying to update this field. However, it will not allow me to update this field because it is a lookup text field. Is there any possible way around this?
Thanks!
Rooey
Updating Access Database From Web!
I have a large Access database (price-catalog) on-line. At the moment I update it by using the web-query in MS Excel. I have included these queries to my self made VB macro that acquires the data from 5 different web sites, cleans the data and compines them to one large database. Then I convert it to Access DB and upload it to my site. (users can now search the database to find the lowest price)
This is pretty complicated task to do each day. So, I was wondering that is it possible to automate this process?
Is it possible to write a script that does this work for me (to schedule the update, executed at nights) so that I don't have to do anything? Just check that the process has been done right.
Or can you suggest some other ways to do this. My site works like Pricesearch.com.
Any suggestions are welcome!
Access Database Updating SLOW
HI... Im using VB6 with Crystal Reports9. I seem to have a problem when it comes to displaying the Information in a Table on my Report. Before i load the report, i first Populate my Database Table with Records, and then the report will use this Table's Records to display the information on the screen using the report viewer.
My Problem is: The last few records of the table is not displayed, because when the report is loaded, the records arent updated to the Table yet, when i look inside the table it;s not their, only about 2s after the update, then the reports will show. So it looks like when i add a record and close my database Table, it takes about 2s before the last few records are visable, only after 2s when i load the report, then all the data shows. Here is my connectionstring info:
Code:
Dim sConn as stirng
dim mConnection as new ADODB.Connection
'Create The Connection String
sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "Database.mdb" & ";Persist Security Info=False"
mConnection.Open sConn
This is how i add a record to the table.As you can see i do close the connection to the table, but the data is only visable inside the table after a few seconds, and this is not good, because the report is instantly loaded after this code is code, by then the records arent visable yet.
Code:
Private Sub SaveOtherFieldsToDatabase()
Dim SubReportOtherFieldsTable As New ADODB.Recordset
'Calculate the Net Salary that must be shown at the bottom of the Salary Report
dbSalaryTotal = (dbTripsTotal + dbYardworkTotal) - (dbDeductionsTotal + dbInsurance)
With SubReportOtherFieldsTable
.Open "SELECT * FROM SubReport_Otherfields", mConnection, adOpenDynamic, adLockOptimistic, adCmdText
.AddNew
!fldTotalSalary = dbSalaryTotal
!fldInsuranceAmount = dbInsurance
!fldDateFROM = DateFROM
!fldDateTO = DateTO
.Update
.Close
Set SubReportOtherFieldsTable = Nothing
End With
End Sub
This is code i use in my form_load event to show my report
Code:
'*** Set and LOAD THE REPORT ***
Set Report = New EmployeeSalaryReport
Report.DiscardSavedData
Screen.MousePointer = vbHourglass
CRViewer91.ReportSource = Report
CRViewer91.ViewReport
Screen.MousePointer = vbDefault
CRViewer91.Zoom (87)
Searching And Updating Database Access
Hey there,
I'm not too sure on how to go about this i would like to
1) Search the database
2) if a matching computername is found in the database
3) overwrite the computername with a new info
Thus far my codes are as such
Rs.Find "PC"
Do While Rs.EOF <> True
Debug.Print "PC Name: "; Rs!PC
Count = Count + 1
Mark = Rs.Bookmark
Rs.Find "PC", 1, adSearchForward, Mark
Loop
How do i continue from here
thank you very much
cheers!
Problems Updating MS Access Database
I have the following code. I am retreiving data from two tables in a database, but want to update one of the fields in one of the tables. It's not liking the TempDyna.Edit code. Any ideas on how to get this to update my field properly?
TempSQL$ = "SELECT T980_DD350.B1A_CONT_NR_TX, T980_REPORT_ID.SENT_DT FROM T980_DD350, T980_REPORT_ID WHERE T980_DD350.K_ID = T980_REPORT_ID.K_ID AND T980_REPORT_ID.K_ID = " & Kid
Set TempDyna = MyDb.OpenRecordset(TempSQL, dbOpenDynaset)
DBEngine.Idle dbFreeLocks
If TempDyna.BOF = False And TempDyna.EOF = False Then
TempDyna.Edit
TempDyna.LockEdits = False
TempDyna("SENT_DT") = Format(Now, "MM/DD/YYYY")
TempDyna.Update
End If
Call dfClose(TempDyna)
Vb Error Updating With Access Database
Good Afternoon.
I am posting this again. Usually I receive a response very quick, but since there were 2 responses due to me posting on the wrong site, maybe it got overlooked. I would really appreciate the help. Thanks in advance.
I get error "3251" (Object or provider is not capable of performing requested operation).
I am able to update Access table when I read sequentially thru the file;
sample code:
strSql = "Abends"
rstAbends.Open strSql, strConn1, adOpenKeyset, adLockOptimistic, adCmdTable
intFlag = 0
Do Until rstAbends.EOF Or intFlag = 1
If rstAbends!JesNumber = txtJesNum.Text Then
If (Len(txtTurnAround.Text) > 0) And
rstAbends!turnaroundaction <>
UCase(txtTurnAround.Text) Then
rstAbends!turnaroundaction =UCase (txtTurnAround.Text)
End If
intFlag = 1
rstAbends.Update
However, when I use the SQL statement to retrieve the record, (which is the correct way to do it since I know the key value!), I get the above mentioned error, which will not even allow me to perform an assignment statement to the field. strjesnumber does have a value.
rstAbends.Open strSql, strConn1, adOpenKeyset, adLockOptimistic, adCmdTable
Set rstAbends = olah_cndb.Execute("Select * from ABENDS WHERE jesnumber = '" & strjesnumber & "'")
'If Not IsNull(txtTurnAround.Text) Then
If (Len(txtTurnAround.Text) > 0) And rstAbends!turnaroundaction <> UCase(txtTurnAround.Text) Then
rstAbends!turnaroundaction = UCase(txtTurnAround.Text)
End If
rstAbends.Update
Thanks in advance
Problem Updating Access Database
Morning,
Have a problem where i am trying to update some tables in access from vb. What it does is Deletes thecontents of a table (WORKS), imports the contents of a csv file( DOESNT WORK SAYS THAT THE TABLE ALREADY EXISTS) and then moves the data from the import table to the actual table it needs to be in(WORKS). What i need to do is to tell it to overwrite the table in the second query! The code is as follows......
Private Sub Form_Load()
Dim cmd As String
Dim sqldelete As String
Dim sqlmove As String
Dim sqlimport As String
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim database As String
Adodc1.Visible = False
sqldelete = "DELETE IMPORT.[Call start], IMPORT.[Call duration], IMPORT.[Ring duration], IMPORT.Caller, IMPORT.Direction, IMPORT.Called_number, IMPORT.Dialled_number, IMPORT.Account, IMPORT.Is_Internal, IMPORT.[Call ID], IMPORT.Continuation, IMPORT.Party1Device, IMPORT.Party1Name, IMPORT.Party2Device, IMPORT.Party2Name, IMPORT.Hold_Time, IMPORT.Park_Time FROM IMPORT;"
sqlmove = "INSERT INTO SMDR ( [Call start], [Call duration], [Ring duration], Caller, Direction, Called_number, Dialled_number, Account, Is_Internal, Continuation, Party1Device, Party1Name, Party2Device, Party2Name, Hold_Time, Park_Time )SELECT IMPORT.[Call start], IMPORT.[Call duration], IMPORT.[Ring duration], IMPORT.Caller, IMPORT.Direction, IMPORT.Called_number, IMPORT.Dialled_number, IMPORT.Account, IMPORT.Is_Internal, IMPORT.Continuation, IMPORT.Party1Device, IMPORT.Party1Name, IMPORT.Party2Device, IMPORT.Party2Name, IMPORT.Hold_Time, IMPORT.Park_Time FROM IMPORT;"
sqlimport = "SELECT * " & "INTO [IMPORT] " & "FROM [Text;database=C:Program FilesAvayaIP OfficeCCCDeltaServerSMDR_Output].[SMDR.csv]"
'create the connection
cmd = "provider=microsoft.jet.oledb.4.0;" & "data source=" & "c:calllogger2002.mdb"
'Establish the connection
Set cn = New ADODB.Connection
With cn
.ConnectionString = cmd
.Open
End With
'Ammend the records
Set rs = New ADODB.Recordset
With rs
.Open sqldelete, cn
.Open sqlimport, cn ' This is the line that doesnt work!!
.Open splmove, cn
End With
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
Any help anyone can offer will be greatly appreciated as this is the very last piece of the puzzle.
Thanks
Glen
Updating A Password To An Access Database
Hi,
i am having a lot of difficulty getting a password top update, when it gets changed.
In the program that i have, there is an option to change your password. To do so you have to put in your current username and password which i can currently do. Then when the new password is entered and the confirmation password is entered and they are right i am trying to write to the database which i cant to.
Have tried many things is there an easy way to do it, i am using a data adapter and dataset to get things happening but this isnt working. Does anyoneone have any suggestions to help me out? or do you have any examples that may be of help?.
cheers
Dan
Error Updating Access Database Via VB Command
Good Afternoon.
I get error "3251" (Object or provider is not capable of performing requested operation).
I am able to update Access table when I read sequentially thru the file;
sample code:
strSql = "Abends"
rstAbends.Open strSql, strConn1, adOpenKeyset, adLockOptimistic, adCmdTable
intFlag = 0
Do Until rstAbends.EOF Or intFlag = 1
If rstAbends!JesNumber = txtJesNum.Text Then
If (Len(txtTurnAround.Text) > 0) And
rstAbends!turnaroundaction <>
UCase(txtTurnAround.Text) Then
rstAbends!turnaroundaction =UCase (txtTurnAround.Text)
End If
intFlag = 1
rstAbends.Update
However, when I use the SQL statement to retrieve the record, (which is the correct way to do it since I know the key value!), I get the above mentioned error, which will not even allow me to perform an assignment statement to the field. strjesnumber does have a value.
rstAbends.Open strSql, strConn1, adOpenKeyset, adLockOptimistic, adCmdTable
Set rstAbends = olah_cndb.Execute("Select * from ABENDS WHERE jesnumber = '" & strjesnumber & "'")
'If Not IsNull(txtTurnAround.Text) Then
If (Len(txtTurnAround.Text) > 0) And rstAbends!turnaroundaction <> UCase(txtTurnAround.Text) Then
rstAbends!turnaroundaction = UCase(txtTurnAround.Text)
End If
rstAbends.Update
Thanks in advance
Updating Single Record In MS Access Database
I have a form that loads records from a database and you can scroll through them. If you come upon a record that does not have a UserID filled in, I have coded the below method to create the user id and for it to populate the text field on the form with the new user id.
My problem is that I also want to update the record with the new userid, but when I try to do this i am getting an exception saying "Object reference not set to an instance of an object".
I'm not sure what I have done wrong, so any suggestions would be appreciated!
**Note
As soon as adapter1.UpdateCommand.CommandText = command1 is processed the exception is caught and it appears that command is nothing...??????
Code:
Private Sub RunMakeUserID()
Dim command1 As String
i = objCurrencyManager.Position
firstName = objDataView.Item(i)("FirstName")
LastName = objDataView.Item(i)("LastName")
phoneExtension = objDataView.Item(i)("Extension")
makeUserID = firstName.Substring(0, 1) + LastName.Substring(0, 1) + phoneExtension
txtUserID.Text = makeUserID
Dim connection1 As OleDb.OleDbConnection
connection1 = New OleDb.OleDbConnection("Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB: Database L" & _
"ocking Mode=1;Data Source=""F:435Lab6NorthwindNorthwind.mdb"";Jet OLEDB:Engine Type=5;Provider=""Micr" & _
"osoft.Jet.OLEDB.4.0"";Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist secu" & _
"rity info=False;Extended Properties=;Mode=Share Deny None;Jet OLEDB:Encrypt Data" & _
"base=False;Jet OLEDB:Create System Database=False;Jet OLEDB: Don't Copy Locale on" & _
" Compact=False;Jet OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet " & _
"OLEDB:Global Bulk Transactions=1")
Try
connection1.Open()
Dim adapter1 As New OleDb.OleDbDataAdapter
command1 = ("Update Employees set UserID = '" & txtUserID.Text & "' where LastName = '" & txtLName.Text & "'")
lblSQL.Text = command1
adapter1.UpdateCommand.CommandText = command1
adapter1.UpdateCommand.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
connection1.Dispose()
End Try
End Sub
Error Updating Access Database Using Visual Basic
Option Explicit
Dim c As New adodb.Connection
Dim cn As New adodb.Connection
Dim cm As adodb.Command
Dim rsnew2 As New adodb.Recordset
Dim rsnew3 As New adodb.Recordset
Private Sub cmd_close_Click()
Unload.me
End Sub
Private Sub cmd_edit_Click()
rsnew3.Open "select * from company", c, adOpenDynamic, adLockOptimistic
If text1.Text = "" Then
MsgBox " enter the company name"
text1.SetFocus
rsnew3.Fields("text1") = text1.Text
End If
If text2.Text = "" Then
MsgBox " enter the company address"
text2.SetFocus
rsnew3.Fields("text2") = text2.Text
End If
rsnew3.Update
MsgBox " add new successful ", vbInformation, "successful"
End Sub
Private Sub Form_Load()
Dim cs As String
c.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:COMION.MDB;Persist Security Info=False")
rsnew2.Open "select * from company", c, adOpenDynamic
Me.text1.Text = rsnew2(2)
Me.text2.Text = rsnew2(3)
End Sub
I am getting message that "edit is successful", but its not updating in database..
What should i do ????
Error Updating Access Database Using Visual Basic
hi everybody
i am trying to access a database and update the changes..
Here is the code...
Code:
Option Explicit
Dim c As New adodb.Connection
Dim cn As New adodb.Connection
Dim cm As adodb.Command
Dim rsnew2 As New adodb.Recordset
Dim rsnew3 As New adodb.Recordset
Private Sub cmd_close_Click()
Unload.me
End Sub
Private Sub cmd_edit_Click()
rsnew3.Open "select * from company", c, adOpenDynamic, adLockOptimistic
If text1.Text = "" Then
MsgBox " enter the company name"
text1.SetFocus
rsnew3.Fields("text1") = text1.Text
End If
If text2.Text = "" Then
MsgBox " enter the company address"
text2.SetFocus
rsnew3.Fields("text2") = text2.Text
End If
rsnew3.Update
MsgBox " add new successful ", vbInformation, "successful"
End Sub
Private Sub Form_Load()
Dim cs As String
c.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:COMION.MDB;Persist Security Info=False")
rsnew2.Open "select * from company", c, adOpenDynamic
Me.text1.Text = rsnew2(2)
Me.text2.Text = rsnew2(3)
End Sub
I am getting message that "edit is successful", but its not updating in database..
What should i do ????
Some Added Records Not Showing When Updating An Access Database
Ok, Here's the Skinny...
I am writing an application that pulls a list of names off of a
server, it runs a command prompt with a batch file, and outputs
to a text file. (There is an erlier post I put on here last week
regarding that portion of it.)
The problem is that when VB reads through the file and adds the
records, it appears to skip some of the records in the begginning
(appearing to be a random amount) I pasted the code below,
any ideas?
below is the code that creates the file
VB Code:
Private Sub Timer2_Timer() Dim ListCMD Dim BatchFile Dim ListLoc Dim lPid As Long Dim lHnd As Long Dim lRet As Long Timer2.Enabled = False BatchFile = App.Path & "atch.bat" ListLoc = App.Path & "list.txt" ListCMD = "c:" & vbNewLine & "cd " & vbNewLine & "cd " & App.Path & vbNewLine & "telalertc.exe -host jorma -list destinations > list.txt" Open BatchFile For Append As #1 Print #1, ListCMD Close #1 BatchFile = "cmd.exe /c " & Chr(34) & BatchFile & Chr(34) lPid = Shell(BatchFile, vbHide) If lPid <> 0 Then lHnd = OpenProcess(SYNCHRONIZE, 0, lPid) If lHnd <> 0 Then lRet = WaitForSingleObject(lHnd, dwMilliseconds) CloseHandle (lHnd) Timer3.Interval = 3000 Timer3.Enabled = True End If End If End Sub
Below is the code that reads the file
VB Code:
Sub ReloadFullList() Dim matrixdb As Database Dim SQLcmd Dim ListFile Dim BatchFile Dim log Set matrixdb = OpenDatabase(Form1.MatrixDBLocation) ListFile = App.Path & "list.txt" BatchFile = App.Path & "atch.bat" With Form1.Adodc2 .ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Form1.MatrixDBLocation & ";Mode=ReadWrite;Persist Security Info=False" .RecordSource = "SELECT * from tblPagers" .Refresh End With SQLcmd = "DELETE * from tblpagers" WriteSQLLog (SQLcmd) matrixdb.Execute SQLcmd Open ListFile For Input As #1 Do Until EOF(1) Line Input #1, log If InStr(1, log, "error", vbTextCompare) Then GoTo ConnectError Exit Sub Else: End If Loop Close #1 Open ListFile For Input As #1 Line Input #1, log Line Input #1, log Do Until EOF(1) Line Input #1, log log = Mid(log, 2, Len(log) - 2) With Form1.Adodc2.Recordset .AddNew !pagers = log .Update End With Loop Form1.Adodc2.Recordset.MoveFirst Close #1 Form1.List1.Clear Do Until Form1.Adodc2.Recordset.EOF = True Form1.List1.AddItem Form1.DataGrid2.Text Form1.Adodc2.Recordset.MoveNext Loop Form1.Adodc2.Recordset.MoveFirst Kill BatchFile Kill ListFile MsgBox "Jorma Full List Update Complete, Dont Forget to Push to Server When done.", vbOKOnly + vbInformation, "Jorma List Update Complete" Unload Form4Exit SubConnectError: Close #1 MsgBox "There was an error connecting to Jorma to retreieve the full list, please try again later." & vbNewLine & vbNewLine & "If the problem persists, please contact your System Administrator", vbOKOnly + vbInformation, "Potential Jorma Issue" Unload Form4 Kill BatchFile Kill ListFileEnd Sub
The part where it skips two lines is the header for "connecting to,
pulling list" blah blah, I dont need that in the database, all I need
is the names.
The text file is complete, but the names in the database seem to
start at a different part of the list, sometimes 3 names down,
sometimes 20 names down... it makes absolutely no sense to
me, I even set up a timer to have it wait 3 seconds before it
reads the list, but that doesnt seem to make a difference either!!
Any suggestions would be greatly apperciated
Datagrid Looping/Updating And Inserting Then Updating?
I am not too familiar with DB programming in VB. I just wanted a quick app, so I decided to give it a shot in VB. I have a datagrid that has 7 columns. One one has to be filled out and 4 can be filled out based on the one that is required. I entered in the required column and then loop through the grid to find other blank fields. If it is blank and it is a column that the value can be determined, it does a few calculations, gets the the text and does a datagrid1.text = <whatever>. The problem is that the column that gets updated also updates the column next to it. So column 1 would have the right info and column 2 would have a copy of column 1. If column 2 isn't blank, I get a Type Mismatch error, and then it is over-written with column 1's info.
The other problem I have is that if I add a row to the datagrid and then search for blank fields, will go back to the beginning and do the first few over again. So if I add 3 new rows, it will loop through the original rows, then go back to the first 3. If I add 7 rows, it does the original, then goes back through the first 7. I can't get it to go to the newly created rows.
Code:
Private Sub Command1_Click()
Dim sFieldName As String
Dim rs As ADODB.Recordset
Dim t As String
Dim i As Integer
sFieldName = DataGrid1.Columns(0).Caption
Adodc1.Recordset.Update
Adodc1.Recordset.Requery
Set rs = Adodc1.Recordset.Clone
i = 0
Do While Not rs.EOF
For d = 0 To 6
DataGrid1.Row = i
DataGrid1.Col = d
If DataGrid1.Text = "" And d = 1 Then
MsgBox i & " " & d
getEnd (i)
DataGrid1.Col = 0
End If
Next d
rs.MoveNext
i = i + 1
Loop
rs.Close
End Sub
Private Function getEnd(ByVal s As Integer) As String
MsgBox "It's called"
Dim f As Integer
Dim d As String
DataGrid1.Col = 0
d = DataGrid1.Text
f = InStr(d, ".")
DataGrid1.Col = 1
DataGrid1.Row = s
DataGrid1.Text = Mid$(d, f + 1, Len(d))
DataGrid1.Col = 0
End Function
Datagrid Looping/Updating And Inserting Then Updating?
I am not too familiar with DB programming in VB. I just wanted a quick app, so I decided to give it a shot in VB. I have a datagrid that has 7 columns. One one has to be filled out and 4 can be filled out based on the one that is required. I entered in the required column and then loop through the grid to find other blank fields. If it is blank and it is a column that the value can be determined, it does a few calculations, gets the the text and does a datagrid1.text = <whatever>. The problem is that the column that gets updated also updates the column next to it. So column 1 would have the right info and column 2 would have a copy of column 1. If column 2 isn't blank, I get a Type Mismatch error, and then it is over-written with column 1's info.
The other problem I have is that if I add a row to the datagrid and then search for blank fields, will go back to the beginning and do the first few over again. So if I add 3 new rows, it will loop through the original rows, then go back to the first 3. If I add 7 rows, it does the original, then goes back through the first 7. I can't get it to go to the newly created rows.
Code:
Private Sub Command1_Click()
Dim sFieldName As String
Dim rs As ADODB.Recordset
Dim t As String
Dim i As Integer
sFieldName = DataGrid1.Columns(0).Caption
Adodc1.Recordset.Update
Adodc1.Recordset.Requery
Set rs = Adodc1.Recordset.Clone
i = 0
Do While Not rs.EOF
For d = 0 To 6
DataGrid1.Row = i
DataGrid1.Col = d
If DataGrid1.Text = "" And d = 1 Then
MsgBox i & " " & d
getEnd (i)
DataGrid1.Col = 0
End If
Next d
rs.MoveNext
i = i + 1
Loop
rs.Close
End Sub
Private Function getEnd(ByVal s As Integer) As String
MsgBox "It's called"
Dim f As Integer
Dim d As String
DataGrid1.Col = 0
d = DataGrid1.Text
f = InStr(d, ".")
DataGrid1.Col = 1
DataGrid1.Row = s
DataGrid1.Text = Mid$(d, f + 1, Len(d))
DataGrid1.Col = 0
End Function
Saving To Access Database
I am taking a class and have to make an address book that can store to an access database. I have not been able to find the save code for the save button click event in my book. And for extra credit I need some help with a search button code. Again this information is not in my book.
Thanks,
John
Saving A Access Database
I am trying to setup my first database using access. I have the code written but when I close my project the data that I entered does not save. I have search this website looking for the answer I know it has to be here I jsut cant find it.
Here is my code.
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'DejarnetteDataSet.Mailing_List' table. You can move, or remove it, as needed.
Me.Mailing_ListTableAdapter.Fill(Me.DejarnetteDataSet.Mailing_List)
End Sub
Private Sub EmployeesBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Validate()
Me.MailingListBindingSource.EndEdit()
Me.Mailing_ListTableAdapter.Update(DejarnetteDataSet.Mailing_List)
End Sub
Private Sub EmployeesBindingNavigatorSaveItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Validate()
Me.MailingListBindingSource.EndEdit()
Me.Mailing_ListTableAdapter.Update(Me.DejarnetteDataSet.Mailing_List)
End Sub
Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
Try
Me.Validate()
Me.MailingListBindingSource.EndEdit()
Me.Mailing_ListTableAdapter.Update(Me.DejarnetteDataSet.Mailing_List)
MsgBox("Update successful")
Catch ex As Exception
MsgBox("Update failed")
End Try
End Sub
Private Sub btnFirstNameSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirstNameSearch.Click
Dim indexNumber As Integer = Me.MailingListBindingSource.Find("FirstName", Me.FindByNameTextBox.Text)
Me.MailingListBindingSource.Position = indexNumber
End Sub
End Class
Thanks in advance for you help.
Two Datagrid Access The Same Database
I have two datagrid which access the same database but with different query command.
When i insert a data into the database the 1st datagrid list all the records just fine.
(i automatically refresh the datagrid so it can list the updated records).
But when i tried to list all the records on the 2nd datagrid, it didn't list the records at all until i close the form and reopen it again, the 2nd datagrid shows the records.
What could be the problem ?
This is my snippet codes :
Code:'This is when i clicked the command button, it will list the records on the 2nd datagrid
'ObjPerkiraan is the object from class CPerkiraan
Private Sub Cmd_Cari_Id_Perkiraan_Induk_Click()
ObjPerkiraan.sql = "Select id_perkiraan,nama_perkiraan from master_perkiraan
where is_Group = -1 order by id_perkiraan"
ObjPerkiraan.dapatkanRsMasterPerkiraan
With DG_Id_Perkiraan_Induk
.Columns(0).Caption = "Id Perkiraan"
.Columns(1).Caption = "Nama Perkiraan"
.HeadFont = "Arial"
.HeadFont.Bold = True
.Visible = Not DG_Id_Perkiraan_Induk.Visible
End With
End Sub
'The method from class CPerkiraan
Public Sub dapatkanRsMasterPerkiraan()
Set rsIdPerkiraanInduk = New ADODB.Recordset
rsIdPerkiraanInduk.CursorLocation = adUseClient
rsIdPerkiraanInduk.Open sqlPerkiraan, con, adOpenKeyset, adLockOptimistic
'rsIdPerkiraanInduk.Resync adAffectAllChapters
Set FrmMasterPerkiraan.DG_Id_Perkiraan_Induk.DataSource = rsIdPerkiraanInduk
FrmMasterPerkiraan.DG_Id_Perkiraan_Induk.Refresh
'Set rsMasterPerkiraan = Nothing
End Sub
Thanks.
Edited by - erc on 3/25/2004 9:30:44 PM
Saving Ink (digital Signature) To Access Database
Hello,
I have a VB6 application and I would like to add a digital signature to one of my module. I just want to create an area for them to sign (using stylus in tablet pc) , save the ink to Access database and able to load the signature to display with the rest of the record details. Can anyone show me a sample code to do this? Appreciate all helps. Thanks.
Saving Listbox Selections To Access Database
HI,
I am a newbie to VB6. I have a small project I am trying to learn on. I have 2 groups of compents on a form with 3 items in group: dirlistbox, filelistbox and a drivelistbox.
What I am trying to accomplish is in one group for the user to select the drive letter, then the directory and finally the file name, hit a button or something and have the path along with the file name stored in an access database.
In the other group, to select the directory path and save it to the access database as well without a file name.
Does anyone know what is needed to do this or point me to a "How to for beginners/dummies" url ?
Thanks
shickey
Saving Check Box Status To A Access Database
I have a simple table that has text and check boxes. When I edit a row on the form the value is not saved to the table unless I go to the next record and then save. If I save the changes prior to going to the next record the changes are not saved. How can I fix this bug?
Saving Contents Of VB Listbox To Access Database
Good evening to all,
My Visual Basic program involves the need to save the contents of a Listbox to an Access database using a Recordset Connection.
The connection is no problem but I cannot figure out the code needed to save the Listbox contents.
Any help would be much appreciated.
Thanks
SKM.
Using A DataGrid With Coded Database Access
Hello, I have been stumped on this problem for a while.
I am need of how to correctly write the code to handle access to a database for a datagrid *without* using the ado data control itself.
I have it down pat how to connect to a database via code only for other controls, but with the grid, I get errors about bookmarks or something.
This is for a program I wish to distribute later, and so cannot have the ADO control hard coded with the location of the database.
I have tried taking an ADO control, setting up the connection string, then cut and paste that connection string to the Form Load sub, so I could change it to use app.path, but leaving the connection string blank (in the properties of the control at design time) errors out.
Any suggestions to this would be greatly appriciated! Thank you for your time.
-Greg
Connecting A DataGrid To An Access Database
Hi All
Please help. I've created the following code to connect a DataGrid to an
Access database using ADO code, but the datagrid is empty at run-time? Any
suggestions?
'Add Questions to the Questions List Box
adComm.CommandText = "tblQuestions"
adComm.CommandType = adCmdTable
Set adRS.Source = adComm
adRS.Open
If Not adRS.EOF Then
adRS.MoveFirst
Set grdQuestions.DataSource = adRS
End If
Thanks
Debbie
Saving MS Access Database To A Tab-Delimited Text File
I am trying to write my microsoft access database out into tab-delimited text file.
However the following code only writes to a unicode text file, by using ADODB.Stream. I wandered if anybody could help me, by stateing how can I write to a tab-delimited text file instead.
Set mstream = New ADODB.Stream
mstream.Open
'write header
mstream.WriteText "Event Id" + vbTab
mstream.WriteText "Day" + vbTab
mstream.WriteText "Time" + vbTab
'write each record in timetable
Do While Not rsTimetable.EOF
mstream.WriteText rsTimetable("Event ID") + vbTab
mstream.WriteText rsTimetable("Day") + vbTab
mstream.WriteText rsTimetable("Time") + vbCr
rsTimetable.MoveNext
Loop
rsTimetable.Close
mstream.SaveToFile Filename, adSaveCreateOverWrite
mstream.Close
Any help would be much apreciated
Many Thanks
Jimbo
Inserting, Saving Records From Flexgrid To Database(access..)
Dear Frnds,
I M Using Ms Access And Vb.6.0.
I Want To Insert Records In Flexgrid And Saving Records Into Table..
So How Can I Use Flexgrid..
Simply, I Have To Save , Insert Data Into Flexgrid..
I M Student And I M Developing One Software On Bank Test Key S/w.
So Plz Help Me..
Plz Give Me Some Link On Flexgrid.bcz I M New To Flexgrid....
Thanx In Advace
Sweethoney
Saving Listview Items Into Access Database....[Urgent]
I have two textbox and one listview in the form(in report mode). List view contains five columns, say, SerialNumber, Products, ProductDescription, Unitprice and Amount. Listview contains many subitems. One textbox contains Customer's Name and Other Contains the Invoice number. How to save all the listview subitems in access database for corresponding customer name and invoice number. Invoice Number is the unique one in the database.??
Looking for the help,
Saracjl
Thankx.
Relations Between DataCombox And DataGrid Using Access Database
Well, my problem is basically:
I have an Access DataBase with information about schools. I built a form with 2 combobox and 1 datagrid. I can´t relationate the 2 combobox. I need:
1º - Select rows from the first combox and put only this information at the second (E.g At the first combobox (ComboCountries) I list all countries. So, when I click at the ComboCountries_click() I need to select one country and after, only the cities of that countries will appear (at the second combobox named ComboCities).
At the same time I need put in a datagrid the information of schools relationated with that 2 combox.
2º When a select one row at the datagrid, how can I create a link to another form showing the information of that selecting row?
Who can help me?
Thanks very much!
EXE Program Don't Populate Access Database Into Datagrid
Hi,
when I copy an exe file to another computer (only window2000 installed, no visual studio and no access installed), the program run but didn't populated data from Access database into the dategrid (It worked with the computer with vb and access installed). Do I need to installed some driver or component to make it work? Thanks.
Need Help With Adding Records To Access Database By Using A Datagrid
I have an Access database installed on my Windows NT4 PC.
I am accessing the database table records from a VB6 program
that I wrote. I have the "Working Model Edition" of VB6
installed on my PC.
I am displaying te contents of a user specified table with a
combination of a datagrid control and an ADO data control.
The code which loads the database table contents into the
datagrid is located in a "module" which is included
with the VB project. The display of the data works fine.
I then modified the program to add a "modification" form and
added the "appropriate" new code to the "global items module".
The modification of table records worked fine.
I then created a form and new code to handle "record additions".
The "add a new record" row is displayed at the bottom of the data
grid (i.e. a blank row with a "*"). However, when I position my
cursor into the "add a new record" row I can't type anything. I
even tried setting the ado data control mode parameter to
"adModeReadWrite" at both design time and run time. This did not
solve the problem.
Here is the code from my "global items module" which handles the
display of the datagrid.
Public Sub AddTableContents(strTableName As String)
' Display the specified table in the form "frmTableAdd"
' inside the DataGrid named "dgrAddGrid" using
' an Adodc control. This grid allows record additions.
frmTableAdd.lblTableAdd.Caption = "Contents of table " & _
strTableName
frmTableAdd.adoTableAdd.CommandType = adCmdTable
frmTableAdd.adoTableAdd.RecordSource = strTableName
frmTableAdd.adoTableAdd.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;User ID=Admin;Data Source=F:Program FilesMicrosoft Visual StudioVB98
ewBiblio.MDB;Mode=Share Deny None"
frmTableAdd.adoTableAdd.Mode = adModeReadWrite
Set frmTableAdd.dgrAddGrid.DataSource = frmTableAdd.adoTableAdd
frmTableAdd.Show vbModal
Exit Sub
End Sub
Any ideas on what I have to change in order to be able to add new records ?
TIA for your help.
Puting Data Into A DataBase (VB6, ADO, ACCESS, DataGrid)
Old in basic/vb but new to this part of database with VB6.
Have created an ACESS Database with several tabels.
Have a VB6 project with several forms.
ACESS, ADO, Jet 4.0 and DataGrid.
If I make a textbox and connect it to the database and say
DataBase.Recordset.AddNew
then I can add text into that textbox and this goes into that database.
So far no problem.
But now I want a value I have in a string, TextString, to be put into the database. In fact I have several such strings I want to be put into various Fields in the new Data.
But I am not able to.
Have tryed to put this text into the TextBox. But this does not get transfered into the database. Strange to me as if I type "manually" it does.
Maybee some settings or ---
So how can I send a textstring direct to a field in the database?
Have a nice day
Per
|