Build Update Query from form (1 Viewer)

craigprice

Registered User.
Local time
Today, 10:23
Joined
Apr 8, 2013
Messages
44
Hi,

Not sure if this is possible at all but I have a table with the following structure;

Code:
01DAY | 01NIGHT | 02DAY | 02NIGHT | 03DAY | 03NIGHT |
Etc etc. up to 31.

These are either filled with null values OR D or N

I am wanting to build an update query which will look at a form where a FROM and TO date are selected. I want to pass the day number of the FROM and day number from TO and add this to the column.

I want the query to then update all columns between the FROM and TO

eg [FROMDATE]DAY and [TODATE]DAY.

Is this possible at all?

Thanks



UPDATE:

I have come across this to make a query on the fly which may work - is there a way in which I can select it to add columns between each other. For example between Dayfrom as day05 and to to as day07 it would also add day06?

Code:
    Dim db As DAO.Database
    Set db = CurrentDb
    Dim qdf As DAO.QueryDef
    Dim newSQL As String
   
    On Error Resume Next
    DoCmd.DeleteObject acQuery, "tempQry"
    On Error GoTo 0
    newSQL = "Select [01night] From [tblrota] WHERE [colleague]=1"
    Set qdf = db.CreateQueryDef("tempQry", newSQL)
 
Last edited:

Ranman256

Well-known member
Local time
Today, 05:23
Joined
Apr 9, 2015
Messages
4,337
Not really the way to do it. Databases want :
Day1, value
night1,value
Day2, value
Etc...

Data is entered like this,THEN you can post results like you showed via Crosstab query.
Use atomic structure.
 

plog

Banishment Pending
Local time
Today, 04:23
Joined
May 11, 2011
Messages
11,643
The issue you posted about is a symptom of a larger problem. You do not have a properly structured database. When you start numerating field names (e.g. 01DAY, 02Day, etc. ) it's time for a new table. Tables should grow vertically (with more rows) and not horizontally (with more columns).

You need a table structured like so:

DayNumber, DayPart
1, Day
1, Night
2, Day
2, Night
3, Day
...


I suggest you read up on normalization (https://en.wikipedia.org/wiki/Database_normalization). Work on setting up your tables properly then tackle what you are trying to accomplish again.
 

Users who are viewing this thread

Top Bottom