Modules

shadowraven

Registered User.
Local time
Today, 13:38
Joined
May 14, 2002
Messages
75
I am very very new to modules and macros and im stuck I know how to use all other bits in access 97 but not these two things.
I would like to know when I have a piece of code in a module how do I then call it with a button from a form or report as every time I try it displays the code and dont run the function its meant to this sounds stupid I know but any help gratefully recieved urgently
 
Can you explain what you are trying to do because that depends on where you put the VB code.
Generally if you are using a button on the form, you can write the code in the 'onClick' property of the button.

Col
 
If you've written a function, you can call it with the OnClick event like ColinEssex describes:

Private Sub Button_Click()
Call functionname

End Sub
 
im trying to get the following code to run when you click on a button in a form.

please explain step by step how you did it so I can attempt to do this with other modules thanx.


********************************************* code need to run below this line.
*********************************************


Option Compare Database
Option Explicit
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _
(ByVal lpstrCommand As String, ByVal lpstrReturnString As String, _
ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long

Public Sub SetCDState(pbState As Boolean)
If pbState Then
Call mciSendString("Set CDAudio Door Open", 0&, 0&, 0&)
Else
Call mciSendString("Set CDAudio Door Closed", 0&, 0&, 0&)
End If
End Sub

' Open CD tray with Command Button
Private Sub cmdClose_Click()
Call SetCDState(False)
End Sub

' Close CD tray with Command Button
Private Sub cmdOpen_Click()
Call SetCDState(True)
End Sub

HTH
RDH
 
Ok here we go

Create a new module and copy in this bit-

Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _
(ByVal lpstrCommand As String, ByVal lpstrReturnString As String, _
ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long

Public Sub SetCDState(pbState As Boolean)
If pbState Then
Call mciSendString("Set CDAudio Door Open", 0&, 0&, 0&)
Else
Call mciSendString("Set CDAudio Door Closed", 0&, 0&, 0&)
End If
End Sub

It doesn't matter what you call it

Then, on a form create 2 command buttons (with the wizard switched off)

In the on click property of one copy this-

Call SetCDState(False)

and in the on click property of the other copy this

Call SetCDState(True)

Thats it

Col
 
I tried this exactly how you said to how do you turn wizzard off and when you say paste code to on click do i have to click on code builder or just paste in to the white box area as im getting an error saying something about a macro. it says can't find Call SetCDState(True)

and the same with the other button it says
can't find Call SetCDState(False)

do I have to paste the code u supplied in the acual moduel tab or do I have to click buid event.

[This message has been edited by shadowraven (edited 05-14-2002).]

[This message has been edited by shadowraven (edited 05-14-2002).]
 
To turn the wizard off - on the toolbox where you get the button from there is a picture of a magic wand. Make sure this is NOT depressed.

The 'on click'property of the button. Double click in the white box and it should say 'Event procedure' Then to the right of the box is a button with ... (3 dots) on it, press that and paste the code in the big white screen that opens up.

Col
 
I have done this got no errors or anything to indicate its wrong but the drive dont open up at all
 

Users who are viewing this thread

Back
Top Bottom