473,395 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Help with looping

13
im trying to get a form to let me change the record im looking at though a text box. This hasnt worked any of the ways ive tried yet but im not the best at vb. my idea was to make a button that returns you to the first value then sends you to the next record X ammount of times. So far i have
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command8_Click()
  2.  
  3. Dim rec As Integer
  4. Dim count As Integer
  5. count = 0
  6. rec = Text12
  7.     DoCmd.GoToRecord , , acFirst
  8.  
  9. Exit_Command9_Click:
  10.     Exit Sub
  11.  
  12. Err_Command9_Click:
  13.     MsgBox Err.Description
  14.     Resume Exit_Command9_Click
  15.  
  16.  Do Until count = rec
  17.     count = count + 1
  18.     DoCmd.GoToRecord , , acNext
  19.  Loop
  20. End Sub
Feb 21 '08 #1
7 1039
debasisdas
8,127 Expert 4TB
are you retriving data from database ?
Feb 21 '08 #2
Clant1
13
are you retriving data from database ?
yes. all im trying to do is make it change the record im looking at. so i thought if it looped the look at next record command it should do that
Feb 21 '08 #3
jamesd0142
469 256MB
If your using a database, and you load a single record into a textbox, when you change the value in the textbox you will need to run some script in sql to update the record...

Such as (example only)

before this works you should store the id of the record in a variable on loading into the textbox.

Expand|Select|Wrap|Line Numbers
  1. update tablename
  2. set fieldname = 'textbox.text' where id = 'IDvariable'
  3.  
Feb 21 '08 #4
jamesd0142
469 256MB
Here's an example in vb.net

Expand|Select|Wrap|Line Numbers
  1. Imports System.Data.OleDb
  2.  
  3. public Class Form1
  4.  
  5.     '---Database Declarations
  6.     Dim Cmd As OleDb.OleDbCommand
  7.     Dim Con As OleDb.OleDbConnection
  8.     Dim Sql As String = Nothing
  9.     Dim Reader As OleDb.OleDbDataReader
  10.     Dim ComboRow As Integer = -1
  11.     Dim Columns As Integer = 0
  12.     Dim Category As String = Nothing
  13.     Dim da As System.Data.OleDb.OleDbDataAdapter
  14.     Dim oDS2 As New System.Data.DataSet
  15.     Dim ID As String = 1
  16.     '---Database Declarations End
  17.  
  18.  
  19.  
  20.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  21.         txtDisplay.Clear()
  22.         oDS2.Clear()
  23.  
  24.         Dim value As String = Nothing
  25.  
  26.         Sql = "select * from Change where [IDVal] = " & "'" & ID & "'"
  27.         Con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\james.durbin\My Documents\reminder.mdb")
  28.  
  29.         Con.Close()
  30.         Cmd = New OleDb.OleDbCommand(Sql, Con)
  31.         Try
  32.             Con.Open()
  33.             da = New OleDbDataAdapter(Sql, Con)
  34.             da.Fill(oDS2, "change")
  35.             If oDS2.Tables("change").Rows.Count = 1 Then
  36.                 txtDisplay.Text = oDS2.Tables("change").Rows(0)("Value")
  37.             End If
  38.         Catch
  39.  
  40.         End Try
  41.     End Sub
  42.  
  43.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  44.         Try
  45.             'Dim StrConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Users\Users.mdb"
  46.             Dim oConn As New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\james.durbin\My Documents\reminder.mdb")
  47.             oConn.Close()
  48.             Dim con As New System.Data.OleDb.OleDbCommand
  49.             con.Connection = oConn
  50.             con.CommandType = CommandType.Text
  51.             con.CommandText = "update change set [Value] = " & "'" & txtDisplay.Text & "'" & " where [IDVal] = " & "'" & ID & "'"
  52.             oConn.Open()
  53.             'display no of rows affected
  54.             con.ExecuteNonQuery()
  55.         Catch
  56.         End Try
  57.     End Sub
  58.  
  59.     Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtID.TextChanged
  60.         ID = txtID.Text
  61.     End Sub
  62. End Class
  63.  
  64.  
my form had 2 textbox's
txtId
txtDisplay

2 buttons
button1
button2

im using an access Database

James
Feb 21 '08 #5
Killer42
8,435 Expert 8TB
im trying to get a form to let me change ...
If you carefully read through the code you posted in message #1, there is no way it can possibly reach the Do loop. Consider line 10 and (assuming there's an On Error Goto that we can't see) line 14. Both of which return control to somewhere else.

By the way, I recommend changing the variable name count. Notice it's shown in a different colour to rec, when formatted here on TheScripts? I think that's because it's a reserved word in VB.
Feb 21 '08 #6
Clant1
13
If you carefully read through the code you posted in message #1, there is no way it can possibly reach the Do loop. Consider line 10 and (assuming there's an On Error Goto that we can't see) line 14. Both of which return control to somewhere else.

By the way, I recommend changing the variable name count. Notice it's shown in a different colour to rec, when formatted here on TheScripts? I think that's because it's a reserved word in VB.
tried what you said first and ended up with

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command8_Click()
  2.  
  3. Dim rec As Integer
  4. Dim cnt As Integer
  5. Dim i As Integer
  6. cnt = 0
  7. rec = Text12
  8.     DoCmd.GoToRecord , , acFirst
  9.  
  10.  Do Until cnt = rec
  11.     cnt = cnt + 1
  12.     DoCmd.GoToRecord , , acNext
  13.  
  14.  Loop
  15. End Sub
which worked. out of interest i did try the others and they worked as well thanks alot guys
Feb 22 '08 #7
Killer42
8,435 Expert 8TB
Glad we could help. :)
Feb 22 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

31
by: da Vinci | last post by:
OK, this has got to be a simple one and yet I cannot find the answer in my textbook. How can I get a simple pause after an output line, that simply waits for any key to be pressed to move on? ...
3
by: frozenee | last post by:
I've noticed that the listings in help don't take you to correct topic. anyone else have this problem? Is there a fix?
4
by: Paul M | last post by:
Larry, i've got an xml file which has multiple cities as the top level item. When i read it in using XMLReader, and define the variables, as below, it finds the correct number of cities in the...
2
by: atreide_son | last post by:
hello all... yes i'm a newbie and i need help. i have an assignment due for class, but I don't know i'm stuck and can't get out from under myself. here's the focus of the program: Write...
4
by: Jeffrey Barrett | last post by:
Can someone tell me why I'm having this problem: When I select drink 5 and deposit too little money, there's a problem with the 'difference' variable. Try to deposit $.80 instead of the full $.85...
15
by: Jay | last post by:
I have a multi threaded VB.NET application (4 threads) that I use to send text messages to many, many employees via system.timer at a 5 second interval. Basically, I look in a SQL table (queue) to...
21
by: asif929 | last post by:
I need immediate help in writing a function program. I have to write a program in functions and use array to store them. I am not familiar with functions and i tried to create it but i fails to...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
1
by: darrel | last post by:
Hi vb master i need help on this here my code: If Combo1(0) = rs.Fields("TimeStart") And Combo4(0) = rs.Fields("TimeEnd") And Combo2(0) = rs.Fields("ROOM") And Combo3(0) = rs.Fields("DAYS")...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.