how to fill down when empty cells in access db [closed] - vba

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
db access table
kindly i need help to fill down with previous string PS: i am a beginner

Your Date field seems to be of data type Text. If so, change that to DateTime.
Then you can run a loop to update the records having no date value:
Dim Records As DAO.Recordset
Dim Sql As String
Dim LastDate As Date
Sql = "Select * From YourTable Order By [Surevey ID]"
Set Records = CurrentDb.OpenRecordset(Sql)
If Records.RecordCount > 0 Then
LastDate = Date ' Adjust if needed.
Records.MoveFirst
While Not Records.EOF
If IsNull(Records!Date.Value) Then
Records.Edit
Records!Date.Value = LastDate
Records.Update
Else
LastDate = Records!Date.Value
End If
Records.MoveNext
Wend
End If
Records.Close

Related

order by charindex >0 and SQL concat [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I want to order Recordset by setting priority when ID is in an array:
This is the comma separated myString which holds a series of ID: ,1,2,4,6,8,12,34,
I use concat to add comma before and after ID so I can compare it against the string:
sql="select * from customers order by case when charindex( concat(','," & id & ",',') , '" & myString & "' )>0 then 1 else 0 end desc"
I get syntax error message. I am not sure if there is error in SQL structure as I used concat in deep structure or there is error in using quote and double quote?
I found the problem when trying to answer #Diado Comment. The parameter ID should be used in SQL context not as a variable in VbScript context. So I have changed the query to this and it works:
sql="select * from customers order by case when charindex( concat(',',id,',') , '" & myString & "' )>0 then 1 else 0 end desc"

Sql table with columns that can store arraylist [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a parameters that contain 6 or more number and can be input with textbox
so for each parameter, put the numbers in a arraylist
like this:
Dim a As New ArrayList
a.Add(Val(B1_Left.Text))
a.Add(Val(B1_Down.Text))
a.Add(Val(B1_Right.Text))
a.Add(Val(BB1_Left.Text))
a.Add(Val(BB1_Down.Text))
a.Add(Val(BB11_Right.Text))
so for each record i have an arraylist parameter that should be insert the row of one column. Which column type should i apply in sql server table to store a vb.net arraylist?
my vb.net code for insert to database:
Dim DBConnection As New SqlConnection(My.Settings.CS)
Dim DBCommand As New SqlCommand
Dim _PID As Integer
Dim _Date As Date
Dim _txt As String
Dim _B1 As ArrayList = a.clone
DBCommand.Connection = DBConnection
DBCommand.CommandText = "insert into TOM_ShaftFix " &
" ( PID, [Date], txt, B1) " &
" VALUES(#PID,#Date,#txt,#B1)"
DBCommand.Parameters.AddWithValue("#pid", _PID)
DBCommand.Parameters.AddWithValue("#Date", _Date)
DBCommand.Parameters.AddWithValue("#txt", _txt)
DBCommand.Parameters.AddWithValue("#B1", _B1)
DBConnection.Open()
DBCommand.ExecuteNonQuery()
DBConnection.Close()
Depending on the version of SQL Server you could store the data as JSON.
In SQL 2016 it is supported natively, alternativelly you could store it as XML.
declare #country nvarchar(max) = '{
"id" : 101,
"name": "United States",
"continent": "North America"
}';
INSERT INTO Countries
SELECT * FROM OPENJSON(#country)
WITH (id int,
name nvarchar(100),
continent nvarchar(100))
MSDN
Depending on the type you could simply store it as comma seperated values.
1,2,3,4,5,6

VBA - SQL query with dates as variable on Oracle DB [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I am performing in VBA an SQL query selecting per date. Everything is working until I specify the dates, as the code below:
conn.Open dbConnectStr
StartDate = "01/01/2015"
SQL_String = "SELECT * FROM database " & _
"WHERE date BETWEEN to_date('01/01/2015','dd/mm/yyyy') and to_date('31/12/2016','dd/mm/yyyy')"
recset.Close
conn.Close
But, when I put in a variable instead of dates I obtain an error multiple-step operation completed with one or more errors. Check each status values.
conn.Open dbConnectStr
StartDate = "01/01/2015"
EndDate = "31/12/2016"
SQL_String = "SELECT * FROM database " & _
"WHERE date BETWEEN to_date('" & StartDate & "','dd/mm/yyyy') and to_date('" & EndDate & "','dd/mm/yyyy')"
recset.Close
conn.Close
Anybody could suggest how to proceed?

MS Access - Select rows according to a field whose values are in an array [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am using MS Access 2007.
I would like to extract data from a table in a database according to some field, say 'car ID'. For every 'car ID' (total of 100 cars), I want to extract all the rows related to that car into an excel spreadsheet in order to operate on it later. Ideally, I would have 100 different spreadsheets in the end, each describing the history of a single car.
Now, since I have a vector of 100 car IDs, I would like to select the car ID automatically as if it was within a for loop, rather than running a query manually 100 times.
I think I should use VBA for that, but since I am new to both MS Access and VBA I am not quite sure of how to handle this.
Any hint would be greatly appreciated.
Thank you very much.
So you need 2 tables. Your main table contains the CarID as the key field and the second table contains all our values/interests. It seems you are set up that way already.
For this example below, you will need to create a select query and save it with the name "mySavedQuery" (It doesn't matter what the select query does at this point because we will change it through the code.)
In the on-click of a command button you could do:
Dim rs As DAO.Recordset
Dim db As DAO.Database
Dim qdf As DAO.QueryDef
Dim strSQL As String
Dim intLow As Integer
Dim intHigh As Integer
Dim i As Integer
Set db = CurrentDb
intLow = 1
intHigh = DMax("CarID", "Table2")
For i = intLow To intHigh
strSQL = "SELECT Table1.CarID, Table2.Interest FROM Table1 INNER JOIN Table2 ON Table1.CarID = Table2.CarID " _
& " WHERE (((Table1.CarID)=" & i & "));"
Set rs = CurrentDb.OpenRecordset(strSQL)
If Not (rs.EOF And rs.BOF) Then
rs.MoveFirst
Set qdf = db.QueryDefs("mySavedQuery")
qdf.SQL = strSQL
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "mySavedQuery", "C:\Users\SClark\Desktop\Survey" & i & ".xls", True
End If
Next i
Set rs = Nothing
Set db = Nothing
Set qdf = Nothing
What is happening here is we determine the minimum CarID = 1 and use the DMAX to find the Max CarID. We then iterate these values and export one Excel sheet per CarID.
This is a down and dirty example but should get you started down the right path...

Adding spaces before a value? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I need to add spaces before a column in SQL.
For example, I have a column with a value "00:99:88:aa". I need to add 3 spaces before the value to have the value " 00:99:88:aa". How would I do this?
You need to apply string concatenation.
For MySQL and MariaDB
SELECT concat(' ', '00:99:88:aa') FROM ...
or in the event of an update
UPDATE ...
SET value = concat(' ', value)
For SQL Server
SELECT ' ' + '00:99:88:aa' FROM ...
or in the event of an update
UPDATE ...
SET value = ' ' + value
For MS Access
SELECT ' ' & '00:99:88:aa' FROM ...
or in the event of an update
UPDATE ...
SET value = ' ' & value
For all the others
SELECT ' ' || '00:99:88:aa' FROM ...
or in the event of an update
UPDATE ...
SET value = ' ' || value
create a new column
alter table <table_name>
add <temp_column> varchar(10)
Update this new column with three space string
update <table_name> set <temp_column> = " "
concatenate the two columns
select concat(temp_column,column1) from <table_name>
OR add a new column with this value
ON MySql TRY:
UPDATE `table` SET `column` = CONCAT(" ", `column`);