MS Access $ in Table - sql

I made a form that adds info.
With rst
.AddNew
.Fields("a") = b.Value
.Update
It usually works fine. But sometimes I need to put a dollar amount in. So I'll put "$3.43" and it will put the entry in twice. Once at the bottom, and once overwriting the top.
I'm fairly sure this has to do with the "$", because that's the only thing that changes from entry to entry, but I can't find anything about it on Google.
Edit: Full Code
Private Sub Command78_Click()
Dim rst As Recordset
Set rst = CurrentDb.OpenRecordset("Service Calls")
With rst
.AddNew
.Fields("Project Name") = proj.Value
.Fields("Service Address") = address.Value
.Fields("Date of Service") = doS.Value
.Fields("Technician") = tech.Value
.Fields("Total Billed") = billed.Value
.Fields("Zip Code") = zip.Value
.Fields("Description of Work") = work.Value
.Fields("Type of Call") = toC.Value
.Fields("Invoice Number") = invoiceNum.Value
.Fields("Ticket Number") = ticketNum.Value
.Update
End With
End Sub

If Total Billed is of Currency (as it should), you cannot insert a string. Thus, remove a $-sign if present:
.Fields("Total Billed").Value = CCur(Replace(billed.Value, "$", ""))

Looks like you have bound the table to the same form in which the Command78_Click fires, check that and remove the code for the Command78_click event if you have actually bound the table to the form.

Related

"NotOnList" event not recognizing that new data has, in fact, been added

This used to work but now it doesn't. Did Microsoft change something?
I'm attempting to understand the behavior of a combo box in MS Access. I created a table named "Colors" with 2 fields: ID (Autonumber, primary key) and Color (short text). I made a form with a combobox with "LimitToList" set to Yes. The Row Source is the table "Colors". For the NotInList event I have the following code:
Private Sub Colors_NotInList(NewData As String, Response As Integer)
Dim rst As DAO.Recordset
If MsgBox(NewData & " is not in list. Add it?", vbOKCancel) = vbOK Then
Response = acDataErrAdded
Set rst = CurrentDb.OpenRecordset("Colors")
With rst
.AddNew
!Color = NewData
.Update
End With
Else
Response = acDataErrContinue
ctl.Undo
End If
End Sub
If I enter a color not in the table I get the prompt to add it to the list. On clicking OK I get the Access error that I must select an item on the list. The new color I just entered does appear on the list and if I select it everything works fine. But I didn't used to have this second step of selecting it after it's been entered.
I've spent way to much time on what should be a simple task. Can anyone help? Thanks!

What is causing the delay between recordset.update and the form/report getting the information?

Short version
I'm entering information in a database and fetching it shortly after, but for some reason, when I enter the information, it isn't immediately entered, so that when I try to fetch it, I get old results. Why does this happen? I thought the operations were synchronous.
Long version
I have a split Access database. At the moment the backend is on my own hard drive to speed up testing, eventually this backend will land on a server. Back when it was a combined frontend/backend database and before I had done a major code refactor (tbh, it was quite the clusterfornication before that), and now this is happening in a number of different scenarios, but pretty much every time I enter information and try to fetch it right after that. Why this happens is a mystery to me, since everything I was reading told me there is no multi-threading in VBA and that everything is synchronous if not specified otherwise, and I haven't enabled any asynchronous options.
Two Examples:
I add a record to the database then refresh the form that contains those new records. I'm not going to post the full code (unless it is deemed necessary), since I've modularized the code a lot. But essentially it boils down to this: the user clicks a button which executes this:
Private Sub Anhang_hinzufügen_Click()
If IsNull(Me.Parent.ID) Then
MsgBox "Bitte erst Felder ausfüllen, und anschließend Anhänge hinzufügen", vbInformation
Else
AnhängeAuswählen Me.Parent.Name, Me.Parent.ID
Me.Form.Requery
End If
End Sub
As part of the AnhängeAuswählen method, the method AddRecord is called:
Function AddRecord(TableName As String, fields() As String, values) As Long
Dim Table As DAO.Recordset
Set Table = LUKSVDB.OpenRecordset(TableName)
Table.AddNew
For i = LBound(fields) To UBound(fields)
If TypeName(Table.fields(fields(i)).Value) = "Recordset2" Then
Dim rs2 As DAO.Recordset2
Set rs2 = Table.fields(fields(i)).Value
If IsArray(values(i)) Then
For j = LBound(values(i)) To UBound(values(i))
rs2.AddNew
rs2!Value = values(i)(j)
rs2.Update
Next j
Else
rs2.AddNew
rs2!Value = values(i)
rs2.Update
End If
Else
Table.fields(fields(i)) = values(i)
End If
Next i
AddRecord = Table!ID
Table.Update
Table.Close
End Function
The record is created, that's not the problem. But when it executes Me.Form.Requery, the new record doesn't appear in the form. Only when I execute Me.Form.Requery a fraction of a second later does the record appear.
I add a record to the database using a form, update some information in the recordset with VBA, then requery the subreport with the records. The record appears immediately, but the details I added programmatically only appear when I execute Me.Parent.Requery a couple of seconds later.
The first form is a data entry form, so that as soon as the data is saved, it's blank in order to create a new record. The previous should then appear in the form. The button to create the new record looks like this:
Private Sub Anmerkung_Hinzufügen_Click()
currentID = Me.ID
mSaved = True
If Me.Dirty Then Me.Dirty = False
UpdateRecord "Anmerkungen", currentID, StringArray("Person", "Datum"), Array(User, Now)
Me.Parent.Requery
End Sub
The UpdateRecord is similar to the AddRecord method:
Function UpdateRecord(TableName As String, ByVal ID As Integer, fields() As String, values)
Dim Table As DAO.Recordset
Set Table = SeekPK(TableName, ID, True)
Table.Edit
For i = LBound(fields) To UBound(fields)
If TypeName(Table.fields(fields(i)).Value) = "Recordset2" Then
Dim subtable As DAO.Recordset2
Set subtable = Table.fields(fields(i)).Value
If IsArray(values(i)) Then
On Error Resume Next
Dim t
t = LBound(values(i))
If Developer Then On Error GoTo -1 Else On Error GoTo Fehler
If Err.Number = 0 Then
For j = LBound(values(i)) To UBound(values(i))
subtable.AddNew
subtable!Value = values(i)(j)
subtable.Update
Next j
End If
Else
subtable.AddNew
subtable!Value = values(i)
subtable.Update
End If
Else
Table.fields(fields(i)) = values(i)
End If
Next i
Table.Update
Table.Close
End Function
Does anyone know why this happens, and how I can prevent it? I could do a bit of a workaround with timers on the forms, so that it refreshes the form a couple of seconds later, but that seems like a kludgy workaround to me, especially considering I don't know how long it specifically takes, and the times could change drastically once the backend is on the server.
Additional information, in case it's necessary:
In the code I've posted I've removed some additional code for error handling and performance logging, but it doesn't have any impact on what's happening otherwise.
When the database is opened, a global variable LUKSVDB As DAO.Database is initialized:
Function ConnectDatabase(Backend As Integer)
Select Case Backend
Case 0: DatenOrt = 'redacted, folder in which the production/beta database is located on the server
Case 1: DatenOrt = 'redacted, folder in which I have a personal testing database on the server
Case 2: DatenOrt = 'redacted, folder in which I have the testing database on my own computer
End Select
Set LUKSVDB = OpenDatabase(DatenOrt & "\LUKS-Verwaltung_be.accdb", False, False, ";pwd=PASSWORD")
End Function
For testing purposes, ConnectDatabase is launched with a value of 2. However, if it's a problem on my own SSD, where latency is just about 0, then I can only assume it will be a problem on the server as well, where the latency is definitely not 0.

Access VBA decode

I am new to VBA code, and working on a project to revised a built MS Access database that has some VBA code built from another person. Can some one explain what the code below would do? My end goal to to create a Data Entry form that would keep previous value from some fields when the users enter the next New Record. Thank you so much.
'Private Sub DocumentTypeCombo1_AfterUpdate()
'Me.DocumentNameCombo1 = Null
'Me.DocumentNameCombo1.Requery
'Me.OrderBy = "Errors DESC"
'Me.DocumentNameCombo1 = Me.DocumentNameCombo1.ItemData(0)
'End Sub
'Private Sub DocumentNameCombo1_AfterUpdate()
'Me.SubcategoryCombo1 = Null
'Me.SubcategoryCombo1.Requery
'Me.OrderBy = "SubCategory DESC"
'Me.SubcategoryCombo1 = Me.SubcategoryCombo1.ItemData(0)
'Me.DocumentNameCombo1.Tag = Me.DocumentNameCombo1
'End Sub
It is commented out, so it does nothing. Even if not, it wouldn't as it misses this line:
Me.OrderBy = "Errors DESC"
Me.OrderByOn = True
If you include the line, it will rearrange the sorting of Me.
To ...
keep previous value from some fields when the users enter the next New Record
you would set the DefaultValue (always a string value) in the AfterUpdate event:
Me!SomeControl.DefaultValue = Chr(34) & Me!SomeControl.Value & Chr(34)

ASP classic, reading and then writing to database

I have a page where a database lookup is done, and if a value is found some response is sent back to the user and then the database value is deleted.
I'm calling my delete sub after I've checked the variable but it's like this never happened, although i know the sub ran since the value is now gone from the database.
It seems like the page is loading twice and on the second pass the database value has gone and so it shows as if the database value was never found, but it had to have been found in order to have deleted it (as this was a condition for running the delete sub).
I realize this sounds insane but I've been on this for 2 days and have no idea what's going on. I've tried disabling caching from within IIS and also changing my code so that a value is posted to the database instead of deleting a record and I still get the same thing where my server seems to check the future value of the database before calling the routine that changes it.
Has anyone seen similar behavior to this when reading and writing to the same record on a single page?
Code:
referer = Request.ServerVariables ("HTTP_REFERER")
session("testcode") = right(referer,16)
testcode = session("testcode")
set objcommand = server.createObject("adodb.command")
objcommand.activeconnection = strconnect2
objcommand.commandtext="SELECT codeval,stamp,used from code where codeval like '" & testcode & "'"
objcommand.commandtype = 1
set objrs = objcommand.Execute
set objcommand = nothing
countvar = 0
While not objrs.EOF
if not objrs("used") = true then
foundcode = true
countvar = countvar+1
end if
objrs.MoveNext
wend
if foundcode = true then
response.write "Found you!"
set objcomm5 = server.createobject("adodb.command")
objcomm5.activeconnection = strconnect2
objcomm5.commandtext = "update code set used = true where codeval like '"& testcode &"' "
objcomm5.commandtype = &H0001
objcomm5.execute
else
response.write "Can't be found!"
end if

Display related matches from database to TextBox popup when we enter some word in textbox in vb.net

i have some problem in Vb.net , i done Google since last 2 days but not getting any related answer of my question , qtn is when user type some text in Text Box so related that text how to display popup just like when we enter some word in Google then Google show all related fields .. guys i m attaching a snapshot please help me ..
i m using vb.net as back end
and MS-Access as front end
Hey guys i got the answer
Step by step (vb.net)
1st declare this as a global
Dim lst As New List(Of String)
Dim rdrOLEDB As OleDbDataReader
Dim MySource As New AutoCompleteStringCollection()
2nd on form load or as per u r logic but make sure it comes only at one time means dont include this code in 3rd step( that is key down)
If ComboBox1.SelectedItem <> "" Then
ComboBox4.Enabled = True
cmdOLEDB.CommandText = "SELECT studentname FROM StudentDetail WHERE std = '" & ComboBox1.SelectedItem & "' "
cmdOLEDB.Connection = cnnOLEDB
rdrOLEDB = cmdOLEDB.ExecuteReader
If rdrOLEDB.Read = True Then
lst.Add(rdrOLEDB.Item(0).ToString)
While rdrOLEDB.Read
lst.Add(rdrOLEDB.Item(0).ToString)
End While
End If
rdrOLEDB.Close()
MySource.AddRange(lst.ToArray)
TextBox2.AutoCompleteCustomSource = MySource
'Auto complete mode set to suggest append so that it will sugesst one
'or more suggested completion strings it has bith ‘Suggest’ and
'‘Append’ functionality
TextBox2.AutoCompleteMode = AutoCompleteMode.SuggestAppend
'Set to Custom source we have filled already
TextBox2.AutoCompleteSource = AutoCompleteSource.CustomSource
Else
MsgBox("please select std.")
End If
3rd step that is text box key down
If e.KeyCode = Keys.Enter Then ' On enter I planned to add it the list
If Not lst.Contains(TextBox2.Text) Then ' If item not present already
' Add to the source directly
TextBox2.AutoCompleteCustomSource.Add(TextBox2.Text)
End If
ElseIf e.KeyCode = Keys.Delete Then 'On delete key, planned to remove entry
' declare a dummy source
Dim coll As AutoCompleteStringCollection = TextBox2.AutoCompleteCustomSource
' remove item from new source
coll.Remove(TextBox2.Text)
' Bind the updates
TextBox2.AutoCompleteCustomSource = coll
' Clear textbox
TextBox2.Clear()
End If ' End of ‘KeyCode’ condition
if its help full then please dont forget to click on point for other peaople search ( parden me for my bad english)