I'm building a room booking system in access, and I need some help with a macro regarding a query.
This is the form people will see when they come to book rooms:
This works fine.
What I've done is create a query that returns, depending on the day, what times a particular room is scheduled for.
This particular query is for Room 111 today. So here, it shows that today, Room 111 is unavailable for Periods 3,4 and 6.
I need to write a macro that looks at each of these lines and blanks out the relevant text box control on the form.
So it should end up looking like this:
I don't know if this is possible using Macros, or if I will need to use Visual Basic. I just need to get the macro/code to say:
"FOR Each Row, IF 111ScheduleCheck.TimeSlot="Period 1", THEN FORMAT 111_P1 TO Background=Black"
"FOR Each Row, IF 111ScheduleCheck.TimeSlot="Period 2", THEN FORMAT 111_P2 TO Background=Black"
etc etc
I've tried this however it doesn't work:
When I run it, I just get this error:
Can somebody help me do this?
Thanks,
Rowan :)
Consider bounding the form to the pivoted query below on a continuous/multiple item form where textboxes will serve as the Period fields with a Room field. Also, there might be room to normalize tables where all Rooms will use one Schedule table, thereby avoiding below union query.
SELECT dT.Room, dT.Day,
Max(IIF(dT.[Time Slot] = 'Period 1', 'Yes', NULL)) AS [Period 1],
Max(IIF(dT.[Time Slot] = 'Period 2', 'Yes', NULL)) AS [Period 2],
Max(IIF(dT.[Time Slot] = 'Period 3', 'Yes', NULL)) AS [Period 3],
Max(IIF(dT.[Time Slot] = 'Period 4', 'Yes', NULL)) AS [Period 4],
Max(IIF(dT.[Time Slot] = 'Period 5', 'Yes', NULL)) AS [Period 5],
Max(IIF(dT.[Time Slot] = 'Period 6', 'Yes', NULL)) AS [Period 6]
FROM
(SELECT 'Room 111' As Room, [Day], [Time Slot] FROM Schedule111
UNION SELECT 'Room 121' As Room, [Day], [Time Slot] FROM Schedule121
UNION SELECT 'Room 122' As Room, [Day], [Time Slot] FROM Schedule122
UNION SELECT 'Room 125' As Room, [Day], [Time Slot] FROM Schedule125) AS dT
GROUP BY dT.Room, dT.Day
And then conditionally format each of the six Period textboxes with background coloring:
[Field Value Is] equal to "Yes".
Finally, filter the form by the day value of the current page using form's OnCurrent trigger event. Be sure the date header control is a true Date formatted textbox:
DoCmd.ApplyFilter , "[Day]='" _
& WeekdayName(WeekDay(Forms!YourForm!YourDateControl,2)) &"'")
I am new in creating procedures in MySql and still learning it. So, I am stuck in creating procedures and need help. The question might seem basic but it will help me learn from basics.
Question:
I want to get the details of salary for each pilot when I specify his pilot_nbr.
Pilot Table consists of
pilot_nbr (primary key)
license_nbr
last_name
first_name
title
address
phone
office_nbr
contract_type
salary
manager_nbr
Sample Data
'701', '7111', 'Dark', 'Jack', '1st officer', '6 street', '6042233445', '789', 'PTE', '145000.00', NULL
'702', '7222', 'Mack', 'Bill', '1st officer', '7 street', '6043344556', '890', 'EMP', '155000.00', '701'
'703', '7333', 'Cheung', 'Charles', '2nd officer', '8street','6044455667','503','PTE','140000.00','701'
'704', '7444', 'Gordon', 'Greg', '1st officer', '9 street', '6045566778', '123', 'EMP', '125000.00', '701'
'705', '7555', 'Basso', 'Nicki', '2nd officer', '5 street', '6046677889', '223', 'EMP', '163000.00', '701'
'706', '7666', 'Vettel', 'Sebast', '1st officer', '5 street', '6046677800', '523', 'EMP', '199000.00','701'
'707', '7777', 'Hawke','Mike','2ndofficer','7street','6046677326',423','EMP','139000.00','701'
Here is what I did and got stuck:
DELIMITER //
CREATE PROCEDURE pilot_Salary_Procedure( IN pilot_Number INT(20), OUT pilot_Salary DECIMAL(10,2))
BEGIN
DECLARE pilot_NummberVariable INT(20);
SELECT pilot_nbr INTO pilot_NumberVariable
FROM pilot
WHERE pilot_nbr = pilot_Number;
END //
I would have done it that way (hoping that this is what you wanted):
DELIMITER //
CREATE PROCEDURE pilot_Salary_Procedure( IN pilot_Number INT(20), OUT pilot_Salary DECIMAL(10,2))
BEGIN
SELECT salary INTO pilot_Salary
FROM pilot
WHERE pilot_nbr = pilot_Number;
END //
You are then able to execute this procedure with
call pilot_Salary_Procedure(701, #salary);
The result then is stored in the session variable salary. You may read the value of this variable by issuing
select #salary;
and thus would get 145000 as result.
see also http://dev.mysql.com/doc/refman/5.7/en/call.html
NB: Be careful with your datatypes: Your notation above suggests that all your values in the table are string-like (for example CHAR or VARCHAR). Whilst this is perfectly okay for attributes like first_name, last_name or phone, it hazardous for other's like salary or even discrete values like the identifiers (pilot_nbr or manager_nbr). Especially salary should be a DECIMAL(15,2) or similar.
INSERT INTO clnt_reports_01 (r_id, cl_no, cl_no, servi, size, vol,
deliver_point, port_, a_port, road, term, compet, speed,
rcomments, stage, meetrating, username, user_status, kids,
hobbies, comments)
VALUES (1, 123123, "test", "test", "test", "test",
"test", "test", "test", "test", 1, "test", "test",
3, 5, "test", "test", 5, "test", "test");
Getting the error -
Error Code: 1136. Column count doesn't match value count at row
Qoute strings with ' and make sure there is the same number of column in both cases (20):
INSERT INTO clnt_reports_01 (r_id,cl_no,servi,size,vol,deliver_point,port_,a_port,road,term,compet,speed,rcomments,stage,meetrating,username,user_status,kids,hobbies,comments)
VALUES (1, 123123, 'test', 'test', 'test', 'test', 'test', 'test', 'test', 'test', 1, 'test', 'test', 3, 5, 'test', 'test', 5, 'test', 'test');
" is treated as identifier (column name).
Also better use INSERT ... SELECT for readability:
INSERT INTO clnt_reports_01 (
r_id,
cl_no,
servi,
size,
vol,
deliver_point,
port_,
a_port,
road,
term,
compet,
speed,
rcomments,
stage,
meetrating,
username,
user_status,
kids,
hobbies,
comments)
SELECT
1 AS r_id,
123123 AS cl_no,
'test' AS servi,
'test' AS size,
'test' As vol,
'test' AS deliver_point,
'test' AS port_,
'test' AS a_port,
'test' AS road,
'test' AS term,
1 AS compet,
'test' AS speed,
'test' AS rcomments,
3 AS stage,
5 AS meetrating,
'test' AS username,
'test' AS user_status,
5 AS kids,
'test' AS hobbies,
'test' AS comments;
EDIT:
You have specified 21 columns and provided only 20 values so there is a mismatch.
cl_no seems to be repeated twice. Remove that.
You need to use single quotes instead of double for text
INSERT INTO clnt_reports_01 (
r_id,
cl_no,
servi,
size,
vol,
deliver_point,
port_,
a_port,
road,
term,
compet,
speed,
rcomments,
stage,
meetrating,
username,
user_status,
kids,
hobbies,
comments)
VALUES (1,
123123,
'test',
'test',
'test',
'test',
'test',
'test',
'test',
'test',
1,
'test',
'test',
3,
5,
'test',
'test',
5,
'test',
'test');
Insert query to specify 21 columns and passing value 20.
You are providing 20 values for 21 columns, maybe because you've listed the column cl_no twice. Even if you fix the column/value count issue, you'll get this error
Error Code : 1136
Column count doesn't match value count at row 1
well, your column count (21) does not match your value count (20) , you're trying to insert 20 things into 21 columns....
This is given away by the error that says
Error Code: 1136. Column count doesn't match value count at row
For this problem :
Error Code: 1136. Column count doesn't match value count at row
cl_no used twice, remove one this column.
You can use single quotes instead of double quotes.
Such as :
"test" -> 'test'
INSERT INTO fgm_pastor(
matriculePastor,
pastorName,
pastorSurname,
pastorBirthdayDate,
birthdayPlace,
pastorFathername,
pastorMothername,
pastorSexe,
pastorPhone,
pastorEmail,
dateConversion,
workBeforeBibleSchool,
rankProbation,
areaOfCalling,
nberYearArea,
nbreYearDistrict,
martialSituation,
nationality,
pastorAdresse,
photoProfil,
raisonIndispoMissionnaire,
id)
VALUES
(
'matriculetest3',
'nom test',
'prenomtest',
'2013-09-12',
'Dagobert',
'mon pere resr' ,
'ma mere test',
'M',
'phone test',
'pastorEmail test',
'2018-12-28',
'infomaticien',
'rank test',
'area test',
1,
3,
'Single test',
'Cameroun test',
'adresse test',
'phototest'
'RAS',
4
);
I have a .sql file that I am importing into my database using phpmyadmin. Each time I have been going through the long list of values and changing the ID so it doesn't conflict with another entry. Since I don't care what the ID is, is there any way to have that auto generated?
Example:
INSERT INTO `my_column` (`id`, `valueone`, `valuetwo`) VALUES
(1, 'some value A', 'some value B'),(2, 'some value C', 'some value D'),(3, 'some value E', 'some value F');
So in the above code, I don't want to type in the "1", "2", and "3".
Can I just leave this blank for it to auto generate? Or is there a symbol that I add instead?
Thanks!
Add AUTO_INCREMENT to id column and remove it from the insert Statement:
INSERT INTO `my_column` ( `valueone`, `valuetwo`) VALUES
( 'some value A', 'some value B'),( 'some value C', 'some value D'),(...