import comma separated numbers to excel from web - html

I am trying to import comma separated numbers in a cell in excel. It looks like this on web:
000002678,000002737,000002827,000004326,000008528
But as soon as I import it in excel it transforms to following:
2,678,000,002,737,000,000,000,000,000,000,000,000,000
How can I maintain the format like it is on web and not treat it as one big number?
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;http://localhost:65076/TestData", Destination:=Range( _
"$A$1"))
.Name = "Test"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlAllTables
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With

#PeterL or user793468 Did you ever solve this? Because i have the exact same problem and the only solution i found was a workaround (that actually can work!)
Set Windows Region and Language settings: "Decimal Settings" from , to . and excel will not treat my case 016448,016501,017612,01... etc as one long number.
If you plan on running the script "autonomasly" then just have those settings in a virtual machine where you run the script.

Related

Download data from dynamic button with VBA

I have some code than download CSV/HTML data from webpages without any problem. The code is something similar to this:
With ActiveSheet.QueryTables.Add(Connection:="URL;" & conexion, Destination:=Range("A1"))
.Name = "FunctionRollupMTO"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
The problem is than the webpage (originally in the variable conexion) is beeing updated and now the data is different. For downloading the data, there is a button for "Download CSV" but the link for that button is not always the same (the URL is generated every time the user press the button).
There is a way to emulate VBA to press that button? Or maybe a different way of connect to that webpage? I've been trying MSXML2 but sincerely I don't really understand its way of work.
Thanks!

How do I set image visible if case is met?

I have a report I'm trying to create. One of the options in the form is Symbol with a dropbox for users to select X, /, or -
If the X is visible, I want the respective image (large red version of symbol) to be visible.
I have built event on Report Load:
Private Sub Report_Load()
Select Case Me.Symbol
Case "X"
Me.ImageX.Visible = True
Me.ImageDash.Visible = False
Me.ImageDiagonal.Visible = False
Case "-"
Me.ImageX.Visible = False
Me.ImageDash.Visible = True
Me.ImageDiagonal.Visible = False
Case "/"
Me.ImageX.Visible = False
Me.ImageDash.Visible = False
Me.ImageDiagonal.Visible = True
Case Else
Me.ImageX.Visible = True
Me.ImageDash.Visible = True
Me.ImageDiagonal.Visible = True
End Select
End Sub
Any ideas on what I'm missing?
As suggested by June, use the On Format event for the relevant section in which the objects reside, as the various object references do not hold values until after the On Load event of the report. For more information regarding the order of events, you may wish to refer to this documentation.
I might also suggest condensing your code to the following:
Private Sub Detail_Format()
Me.ImageX.Visible = Me.Symbol = "X"
Me.ImageDash.Visible = Me.Symbol = "-"
Me.ImageDiagonal.Visible = Me.Symbol = "/"
End Sub

Rearranging Boolean equations

If I have an equation x=y&z (boolean AND) is there a way of rearranging this function so as y=x?z. In a similar fashion to normal algebra that x=y+z can be rearranged as y=x-z.
Similarly, can x=y|z (boolean OR) be rearranged to something y=x?z?
It is easy to prove that such inversion operators cannot exist.
For the AND case:
false = true & false ⇒ true = false ? false
false = false & false ⇒ false = false ? false
But false ? false cannot be true and false at the same time, so there cannot be an operator ? with the desired property. ∎
For the OR case:
true = true | true ⇒ true = true ? true
true = false | true ⇒ false = true ? true
But true ? true cannot be true and false at the same time, so there cannot be an operator ? with the desired property. ∎

ACCESS : VBA Code Button Visibility not working

I have a problem in hiding my buttons and not working mostly is when the button itself was clicked, it supposed to be hidden.
I have a code below from one of my buttons but most of the button visibility codes are not working. I tried to add:
DoEvents
but still don't work. I don't know what the problem is. Some Enable properties were working but some are not.
Private Sub cmdSave_Click()
If MsgBox("Are you sure to save record?", vbYesNo, "Save Record") = vbYes Then
DoEvents
imgPic.Enabled = False
txtLRN.Enabled = False
txtLN.Enabled = False
txtFN.Enabled = False
txtMN.Enabled = False
txtS.Enabled = False
txtA.Enabled = False
txtBD.Enabled = False
txtBP.Enabled = False
txtMT.Enabled = False
txtIP.Enabled = False
txtRG.Enabled = False
txtAH.Enabled = False
txtAB.Enabled = False
txtAM.Enabled = False
txtAP.Enabled = False
txtF.Enabled = False
txtM.Enabled = False
txtGN.Enabled = False
txtGR.Enabled = False
txtCN.Enabled = False
txtR.Enabled = False
DoEvents
cmdSearch.Visible = True
cmdFirst.Visible = True
cmdPrev.Visible = True
cmdNext.Visible = True
cmdNext.Visible = True
cmdLast.Visible = True
cmdNew.Visible = True
cmdDelete.Visible = True
cmdEdit.Visible = True
DoEvents
cmdSave.Visible = False
cmdCancel.Visible = False
DoEvents
End if
End Sub
This simplified version of your procedure will trigger error #2165, "You can't hide a control that has the focus."
Private Sub cmdSave_Click()
Me.cmdSave.Visible = False
End Sub
During cmdSave_Click, cmdSave has focus, so you can't hide it without first moving focus to another unhidden control. This version will avoid that error:
Private Sub cmdSave_Click()
Me.cmdSearch.Visible = True
Me.cmdSearch.SetFocus
Me.cmdSave.Visible = False
End Sub
In similar cases, I've found that you need to specify the form reference ("Me.").
So try (for example)
Me.cmdCancel.Visible = True
In other words specify "Me." in front of the control name.

"Add Record" gives "Can't go to specified record" after first use Access

I have a command button in a form that allows users to add a new record. The command only works the first time you click it after the form is opened. I can navigate through the records without any errors and the first time you add a record after the form is opened will not give errors. Once you try to add a second record, the "Can't go to the specified record" error message is displayed.
I can make edits in the query without a problem and I can edit things without a problem. If I close out of the form and reopen it I can add a new record without issues. Anyone have ideas?
Using VBA, it's the standard add-new code, nothing else. Posted all the code for this form below. Some of the command buttons listed are in macros, don't know if that makes a difference.
Private Sub add_Click()
DoCmd.GoToRecord , , acNewRec
End Sub
Private Sub edit_info_Click()
Date_of_Echo.Locked = False
ID.Locked = False
AoV.Locked = False
AI.Locked = False
MR.Locked = False
TR.Locked = False
TR_velocity.Locked = False
PA_pressures.Locked = False
LVeDD.Locked = False
LVeSD.Locked = False
RV_function.Locked = False
comments.Locked = False
Me.next.Visible = False
Me.previous.Visible = False
Me.first.Visible = False
Me.last.Visible = False
Me.add.Visible = False
Me.save.Visible = True
Me.save.SetFocus
Me.edit_info.Visible = False
End Sub
Private Sub Form_Current()
If Me.NewRecord Then
Me.recordcounter.Caption = "New Record"
Me.next.Visible = False
Me.previous.Visible = False
Me.first.Visible = False
Me.last.Visible = False
Me.add.Visible = False
Me.edit_info.Visible = False
Me.save.Visible = True
Date_of_Echo.Locked = False
ID.Locked = False
AoV.Locked = False
AI.Locked = False
MR.Locked = False
TR.Locked = False
TR_velocity.Locked = False
PA_pressures.Locked = False
LVeDD.Locked = False
LVeSD.Locked = False
RV_function.Locked = False
comments.Locked = False
Else
Me.recordcounter.Caption = "Record " & Me.CurrentRecord & " of " & Me.Recordset.RecordCount
Me.next.Visible = True
Me.previous.Visible = True
Me.first.Visible = True
Me.last.Visible = True
Me.add.Visible = True
Me.edit_info.Visible = True
Me.save.Visible = False
End If
End Sub
Private Sub save_Click()
DoCmd.save
Me.previous.Visible = True
Me.first.Visible = True
Me.last.Visible = True
Me.next.Visible = True
Me.add.Visible = True
Me.edit_info.Visible = True
Me.recordcounter.Caption = "Record " & Me.CurrentRecord & " of " & Me.Recordset.RecordCount
Me.add.SetFocus
Me.save.Visible = False
Date_of_Echo.Locked = True
ID.Locked = True
AoV.Locked = True
AI.Locked = True
MR.Locked = True
TR.Locked = True
TR_velocity.Locked = True
PA_pressures.Locked = True
LVeDD.Locked = True
LVeSD.Locked = True
RV_function.Locked = True
comments.Locked = True
End Sub
Private Sub next_Click()
On Error GoTo Err_cmdLastRecord_Click
Me.AllowAdditions = False
DoCmd.GoToRecord , , acNext
Exit_cmdLastRecord_Click:
Exit Sub
Err_cmdLastRecord_Click:
MsgBox " There are no more records ", vbExclamation, ""
Resume Exit_cmdLastRecord_Click
End Sub
My first thought is that your record isn't saving before you try to go to a new record so try this and see if it fixes the issue.
Private Sub add_Click()
If Me.Dirty Then
Me.Dirty = False
End If
DoCmd.GoToRecord , , acNewRec
End Sub
If anyone is still having this problem, I can't explain why it's happening, but here's a work around:
Reset the AllowAdditionsProperty on the form:
Me.[form_name].Form.AllowAdditions = False
Me.[form_name].Form.AllowAdditions = True
This was a very strange issue because my code had been working fine for weeks. I was using something like this:
Me.frm.SetFocus
DoCmd.GoToRecord , , acNewRec
!Field1 = value1
!Field2 = value2
It was working great, and then out of the blue I started getting the "Can't go to Specified Record" error, even though I had made no changes to the code. The form settings were fine and I could add records all day long in the underlying table. I even checked the form's AllowAdditions property in the Immediate window, and that showed it was set to True. But I tried this work around, and it worked.
Now I add those two lines after every instance of Docmd.GoToNewRoecord, acNewRecord and it's working.
Another thing I have mentioned with the same problem is that you should check the Form data source query. Are all the FIELDS available, are the JOINS correct?
In my case I changed indexed joins from text fields to numeric and it needed update also in Form Data source query.