How to do these things ? (1 Viewer)

Cyberslam

Registered User.
Local time
Yesterday, 16:31
Joined
Sep 1, 2005
Messages
35
Hello all !

I am kinda new to access and made a transport database but it needs some changes which are out of my knowledege so i am hoping that you guys can help me out. There are the 2 things that i would like to do in my forms:

1=, I have a form where all the new cars are added to DB. Fields are Vehicle Code, Type, Brand, Model and Model year. Then I have a transaction form where vehicles are either assigned to employees or to garage etc.. What i would like to do in this form is that when i select a Vehicle Code, the remaining fields i.e. Type, Brand, Model and Model year of that partcular Vehicle Code should appear in thier respective fields of the transaction form.

2=, Now a little difficult part, in the same transaction form i want a field where the name of the current username appears and also a field with current date.

Now moving on to Transaction Type thingy. I want to two options button ( Issue Vehicle and Cancel Vehicle). If option " Issue Vehicle" is selected, a field i.e. a combo box consisting of To Employee and To Garage appears. And then when "To Employee" is selected two fields i.e. Employee No. and Name appear in a kind of frame.( data of both these fields are in other table and will appear in combox boxes). When "To Garage" is selected a field "reason" appear in a frame in place of above stated two fields.

I hope i am making some sense. I know i have to make a table for all these fields but dunno how to do all these things in forms..

Looking forward to your replies and thanks in advance.
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 19:31
Joined
Feb 19, 2002
Messages
43,302
Whenever you need fields from two tables to populate a form/report, the best alternative is to create a query that joins the two tables. Use that query as the RecordSource for the form/report.
 

Cyberslam

Registered User.
Local time
Yesterday, 16:31
Joined
Sep 1, 2005
Messages
35
Yeah but how do i implement it on my first 1st and 2nd questions ?
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 19:31
Joined
Feb 19, 2002
Messages
43,302
That is the answer to both questions. The answer to the third, unnumbered question is to add code to the AfterUpdate event of the option control and to the AfterUpdate event of the WhereTo control. You also need both pieces of code in the Current event of the form.

Code:
If Me.Option = "Issue Vehicle" then
    Me.WhereTo.Visible = True
Else
    Me.WhereTo.Visible = False
End If
Code:
 If Me.WhereTo = "To Garage" Then
    Me.Reason.Visible = True
Else
    Me.Reason.Visible = False
End If
 

Cyberslam

Registered User.
Local time
Yesterday, 16:31
Joined
Sep 1, 2005
Messages
35
^ Thanks for the help Pat Hartman.

But whats "WhereTo" in the code ?

And do i have to put both of these codes in expression builder of both the options control ( i.e. Option 1 and Option 2 ) ? Or first code in the Option 1 and the other code in the Optios 2 ?

I am new to these access coding so please bear it with me.
 
Last edited:

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 19:31
Joined
Feb 19, 2002
Messages
43,302
You need to change "option" and "whereto" to your own field names.

To add code to an event, click the builder button and choose code. Access will build the procedure header and end. You place the suggested code between the two lines Access created.
 

Cyberslam

Registered User.
Local time
Yesterday, 16:31
Joined
Sep 1, 2005
Messages
35
^ it isn't working. I have created two options "Issue Vehicle" and "Cancel Vehicle" and edited the code like this:

For "Issue Vehicle" option:

Code:
If Me.Issue Vehicle= "Issue Vehicle" then      
Me.Issue Vehicle.Visible = True  Else      
Me.Issue Vehicle.Visible = False  
End If

For "Cancel Vehicle" option:

Code:
If Me.Cancel Vehicle = "Cancel Vehicle" Then      
Me.Reason.Visible = True  Else      
Me.Reason.Visible = False  
End If

The image attached is how my form looks like. As i explanied earlier in my first post, when "Issue Vehicle" is selected, all the fields that i need should appear in a kind of separate frame ( i have bound object frame in my form , is it correct ? ) and same for the "Cancel Vehicle" option.
 

Attachments

  • DRC_DB.JPG
    DRC_DB.JPG
    20.2 KB · Views: 133
Last edited:

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 19:31
Joined
Feb 19, 2002
Messages
43,302
bound object frames are for displaying pictures. You probably want to create subforms and display one subform or the other. To do this, add the subform control to the main form and instead of toggling it's visible property, put the name of the subform you want to be visible in the subform controls SourceObject property.

Me.SubControl.SourceObject = "subformName"
 

Cyberslam

Registered User.
Local time
Yesterday, 16:31
Joined
Sep 1, 2005
Messages
35
Pat Hartman, i really appreciate your help but the problem is that i am kind of a beginner in Access and i would be really greatful to you if you can explain in some steps ( a kinda detail ).

Thanks once again for your help and i am really looking to your reply.
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 19:31
Joined
Feb 19, 2002
Messages
43,302
It is considered poor practice to use special characters or embedded spaces in column names and while you're at it, avoid using function and property names as well.
Code:
If Me.Issue_Vehicle= "Issue Vehicle" then      
    Me.Issue_Vehicle.Visible = True  Else      
    Me.Issue_Vehicle.Visible = False  
End If
I replaced the offending characters in your names with underscores, which is what VBA does. When you use the Me. syntax, you should see your field and control names in the list. If you don't see your name, you have spelled it incorrectly.

The alternative is to surround all names with offending characters within square brackets. But you will loose intellisense if you do this.
 

Users who are viewing this thread

Top Bottom