Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

access database updating problems with GOTFOCUS field

Status
Not open for further replies.

trimakassi

Programmer
Aug 5, 2005
20
MA
Hi everyone,

I am new to programming and would need some help, I have an access database connected to my vb.net program. The user in my program inputs the txtdate, txtAmount, cboCategory,cboStore,txtReceipt, and txtMemo.
example of ideal case:

date.txt 06/12/05
Amount.txt 300$
Category.cbo Clothing
Store.cbo Hugo Boss
Receipt.txt 838923
Memo.txt Present

example of a new case where I have problems:

date.txt 06/12/05
Amount.txt 300$
Category.cbo 1Groceries
Store.cbo __________'gofocus= here it should add Groceries to the Dsstores database and prompt for a New Store so that it store it. I get an error saying that there might be a duplicate in the database, When I check the database it the New Category is added together with the New Category Code and the Store Code but no Store Name

Receipt.txt _______
Memo.txt _______


Here is the code, i have a feeling that the gotfocus method runs more than once before it goes threw the whole procedure

Private Sub cboStore_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboStore.GotFocus
Dim x As Integer = 0
'category converted to string
Dim cat As String
Dim found As Integer

'GETTING THE CATEGORY AND UPLOADING THE NEW STORE LIST

'If the user doesn't type a 1 before the category that means the Category already exists
If cboCategory.Text.Chars(0) <> "1" Then

'clearing the store fields
cboStore.Items.Clear()
'Grouping by Category requested Category
Dsstores2.Tables(0).DefaultView.RowFilter = "CatName = '" & cboCategory.Text & "'"
'Dsstores2.Tables(0).DefaultView.RowFilter = "CatName= 'cboCategory.text'"
'Sorting the Stores
Dsstores2.Tables(0).DefaultView.Sort = "Store"
cat = CStr(cboCategory.Text)

'x=0
'Filling in the sorted Stores in the combobox
While x <> Dsstores2.Tables(0).DefaultView.Count - 1
cboStore.Items.Add(Dsstores2.Tables(0).DefaultView.Item(x)(3))
x += 1
End While

'if the category field is empty then prompt the user
ElseIf cboCategory.Text = "" Then

MsgBox("input Category")

'if the user inputs 1 prior to the category then the new category/Store method is innitiated
ElseIf cboCategory.Text.Chars(0) = "1" Then

'prompt the user for the store name because it needs this new store name to add it to the database
inputfrm.Show()

'Inputing == NEW CATEGORY AND NEW STORE ==
Try
OleDbConnection1.Open()
Dim command As String
'store new id,last row, category new id
Dim s, lasti, catcode As Integer

lasti = Dsstores2.Tables(0).Rows.Count - 1
catcode = Dsstores2.Tables(0).Rows(lasti)(0) + 1
s = Dsstores2.Tables(0).Rows(lasti)(2) + 1

command = "insert into dsstores([Category],[CatName],[Store],[StoreName])" & " values ('" & catcode & "','" & CStr(cboCategory.Text).Remove(0, 1) & "','" & s & "','" & CStr(cboStore.Text) & "')"

OleDbDataAdapter2.InsertCommand.CommandText = command

' do the insert
OleDbDataAdapter2.InsertCommand.ExecuteNonQuery()

Catch exceptionObject As Exception
MessageBox.Show(exceptionObject.Message)
Finally
OleDbConnection1.Close()
End Try

txtReceipt.Focus()


Else
'If an unknown category was inputed then say so
MsgBox("Please input Valid Category")
Exit Sub
End If

End Sub
 
I think the problem is in this line:

inputfrm.Show()

The problem is that the GotFocus code continues executing after inputfrm.Show() is called. Try changing it to this:

inputfrm.ShowDialog()

ShowDialog pauses code execution in the calling procedure until the form called is closed.


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
thanks that worked, But i have another question is there anyother way to make a lostfocus run once or pause.

thankss Jebenson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top