Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get one record a time into a form

Status
Not open for further replies.

Oderbang

Technical User
Dec 18, 2005
8
GB


Basicly i'v got a calendar that iv made a procedure to highlight each day between and including a start and end date.
now what i need to do is
Phudo code following:

Get first date.Fdate
Get second date.Sdate
Highlight between and including fDate & Sdate
Do
Get next Date.Fdate
Get next Date.Sdate
Highlight between and including fDate & Sdate
Untill end of records (or file or what ever you call it)

 
iv maneged to make the procedure to highlight all the dates on the calnder now all i need to do is call all the dates in i have a few problums though
1. the procedure work using 2 text boxes (first date and secound date) you can enter 1 date then the other date and it will highlight all the dates between the thouse 2 dates the problum is i dont know how to read al the dates from the table here is what i have

Code:
Private Sub Command1_Click()
FirstDate = (TxtFDate.Value)
txtFD.Value = Day(FirstDate)
TxtFM.Value = Month(FirstDate)
TxtFY.Value = Year(FirstDate)
'MsgBox (FirstDate)
SecondDate = (TxtSDate.Value)
TxtSD.Value = Day(SecondDate)
TxtSM.Value = Month(SecondDate)
TxtSY.Value = Year(SecondDate)
'MsgBox (SecondDate)
If FirstDate > SecondDate Then
MsgBox ("Please enter a secound date thatis grater than the first date")
Else
    Do
       Calendar0.SetHighLightDay TxtFY.Value, TxtFM.Value, txtFD.Value, RGB(255, 0, 0)
       FirstDate = FirstDate + 1
       txtFD.Value = Day(FirstDate)
       TxtFM.Value = Month(FirstDate)
       TxtFY.Value = Year(FirstDate)
    Loop Until FirstDate = SecondDate + 1
End If

'FirstDate = FirstDate + 1
'MsgBox (FirstDate)
End Sub

'Calendar0.SetHighLightDay txtHYear.Value, txtHMonth.Value, txtHDay.Value, RGB(255, 0, 0)
'End Sub

here is the a image of the form that goes with it
hform.gif



here is the same form in design veiw
hdform.gif


basicly i need to call all dates up to highligh when a perticuler car is being rented here is my table

RentalID CarID Deposite StartDate EndDate
rent1 car1 10 1/12/2005 5/12/2005
rent2 car1 10 7/12/2005 11/12/2005
rent3 car1 10 16/12/2005 20/12/2005
rent4 car2 15 8/12/2005 16/12/2005
ect...

basicly i want to call all the startDates and all the EndDates into the procedure one at a time for a perticuler carID so the proceduer can highligh all the dates that the car is booked on i want this to be done on the form load (or when i select a new carID) so it can highlight all the dates for that car

PLEASE PLEASE HELP
 
Oderbang, are you familiar with opening and reading recordsets?
 
Maybe something like this. Not sure how you want the interface. I used DAO because at home I have A97(okay I am cheap). But you could/should use ADO.

I slightly modified your private subroutine to this accepting 2 arguments. I made it public so I could put it in a module giving it more useability. I did not test your sub to see if it works.
Code:
Public Sub createCalendar(FirstDate As Date, SecondDate As Date)
  your calendar code
end sub
Now I built another routine that I pass in the vehicle ID.
I used your field names and called the table, tblRentals.
Code:
Public Sub AllDatesForVehicle(strCarID As String)
  Dim rs As DAO.Recordset
  Dim strSql As String
  Dim dtmStartDate As Date
  Dim dtmEndDate As Date
  strSql = "Select * from tblRentals where CarID = '" & strCarID & "'"
  Set rs = CurrentDb.OpenRecordset(strSql)
  Do While Not rs.EOF
    dtmStartDate = rs.Fields("startDate")
    dtmEndDate = rs.Fields("endDate")
    Call createCalendar(dtmStartDate, dtmEndDate)
    rs.MoveNext
  Loop
End Sub
This is how I tested it, obviously you would call it from your form.

Public sub Test()
Call AllDatesForVehicle("car1")
Call AllDatesForVehicle("car2")
End sub

I am not sure if this answers your question.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top