Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

VBA Help


  • Please log in to reply

#1
Ph0eNiX

Ph0eNiX

    New Member

  • Member
  • Pip
  • 6 posts
First let me start off by saying I am totally new to both access and vb...that being said here is my problem:
in access I have a database created with 3 forms on it.... the main form we will call phaFRM on the pha form there is a gender section, what i would liek to be able to do is when you check th ebox next to male the corresponding form (maleFRM), and if the female box is checked then the corresponding form (femaleFRM) to open ... if they have to open in a seperate window thats ok, but it would be awesome to figure out how to get them to open in the subform section... is this possible or am I totally crazy??Any help at all (even a point to a tutorial on line) would be greatly appreciated... and by the ay I'm not askin for someoen to do the work for me... just point me in the right direction is all. Thanks
Ph0eNiX
  • 0

Advertisements


#2
Comnir

Comnir

    Member

  • Member
  • PipPipPip
  • 141 posts
You need to write the code to open the form in the OnClick event of each checkbox. You have to double-click each checkbox, to open the code window. E.g. lets choose chkMl (Checkbox for male).

OnClick for chkMl:
If (chkMl.Checked) Then ' The checkbox is checked
   Load maleFRM ' We load the form
   maleFRM.Visible = True ' And make it visible
  End If

You need to do the same for chkFm
  • 0

#3
Ph0eNiX

Ph0eNiX

    New Member

  • Topic Starter
  • Member
  • Pip
  • 6 posts
Private Sub malechk_Click()
If (malechk.Checked) Then ' The checkbox is checked
   Load frm_male ' We load the form
   frm_male.Visible = True ' And make it visible
  End If
End Sub
Creates the following errorerror.jpg
when i click ok then the line Private Sub malechk_Click() is highlighted as well.

Edited by Ph0eNiX, 28 May 2006 - 01:38 PM.

  • 0

#4
Comnir

Comnir

    Member

  • Member
  • PipPipPip
  • 141 posts
Sorry, checkbox doesn't have the 'checked' property but 'value'. Hence, you should check:
If (malechk.Value) Then

  • 0

#5
Ph0eNiX

Ph0eNiX

    New Member

  • Topic Starter
  • Member
  • Pip
  • 6 posts
Did that got this:
Run-Time error '424'
Object required, clicked ok and the "Load frm_male ' We load the form" line was highlighted.... I played around with it a bit and actually got a macro to do what i wanted to do... thank you though for the help. I really do appreciate it.

Edited by Ph0eNiX, 28 May 2006 - 11:31 PM.

  • 0

#6
Comnir

Comnir

    Member

  • Member
  • PipPipPip
  • 141 posts
Are you sure it wasn't supposed to be 'maleFRM'? It seems to be the problem, according to the error message. Anyway, you are welcome :-D.
  • 0

#7
Ph0eNiX

Ph0eNiX

    New Member

  • Topic Starter
  • Member
  • Pip
  • 6 posts
Im back!.... turns out that didn't really fix anything.... the check boxes werent being saved and the data wasn't being transferred... made a drop down menu instead.... now the original problem is back.I have the drop down menu named [Gender], i have 3 forms. frm_male, frm_female, and frm_pha... the [Gender] is on frm_pha, how do I get it to open the corresponding form when the gender is selected? (ie if they pick male the male form opens up)???????????????????????

Edited by Ph0eNiX, 10 June 2006 - 11:23 PM.

  • 0

#8
Hai Mac

Hai Mac

    Member

  • Member
  • PipPipPip
  • 260 posts
Hello,
I am not exactly VBA, but I do VB. Firstly, I would like to revert to the original idea of yours. I would say that it would be nice if a subsection of the form appeared instead of a new form appeared. Why?
  • firstly, it is annoying
  • secondly, it makes data transfer between the two forms complicated
  • thirdly and most importantly, I don't think it is possible to open multiple forms in VBA
Now how to do it:

Enlarge your form so that you can accommodate the two extra subsections with the additional gender options. Create a FRAME for each. Now place your neccessary controls on both frames. In the Property Window, select the property Visible and set it false for both frames. You will still see them while designing, but when you run it, they disappear. Now add this code to your ComboBox

Private Sub ComboBox1_Change()
	If ComboBox1.Value = "Male" Then
		Frame1.Visible = True
		Frame2.Visible = False
	ElseIf ComboBox1.Value = "Female" Then
		Frame1.Visible = False
		Frame2.Visible = True
	End If
End Sub

:whistling: I hope the code is self-explanatory. If in doubt, just ask :blink:
  • 0

#9
Ph0eNiX

Ph0eNiX

    New Member

  • Topic Starter
  • Member
  • Pip
  • 6 posts
BEAUTIFUL! Everything is going perfect so far, one last tiny problem (ain't that what we always say?)
Let's say I have to fields on a form, one is a date box (we will call it date), and the other is a result box (we will call it result). What I am tryin to do is this: The result box needs to be blacked out(still visible but not active) until the date box is filled in. Now I thought ok no problem... I figured out how to do a "if isnull", and getting other fields to black out was figured out, why not try this: By the way I put this "On Current" for the form

Private Sub Form_Current()
If IsNull([lipid]) Then
[cholesterol].Visible = False
[triglyceride].Visible = False
[ldl].Visible = False
[hdl].Visible = False
Else
[cholesterol].Visible = True
[triglyceride].Visible = True
[ldl].Visible = True
[hdl].Visible = True
End If
End Sub


Obviously it didn't quite work out for me or else I wouldn't be coming to the great geek gods for help.... anyone have any suggestions?

Edited by Ph0eNiX, 15 June 2006 - 09:48 PM.

  • 0

#10
Hai Mac

Hai Mac

    Member

  • Member
  • PipPipPip
  • 260 posts
Try If lipid.text = "" then instead of IsNull. Null and an empty string can be different things...
  • 0

#11
Ph0eNiX

Ph0eNiX

    New Member

  • Topic Starter
  • Member
  • Pip
  • 6 posts
Back yet again, some weird stuff happening with this... I got it all fixed to work the way I want... started entering the info and when I got to the second patient it says someone else change the form since I save it last...no matter what I pick (drop changes, save changes, copy to clipboard) when the message goes away all of the english text gets turned into chinese characters.... is there anyone out there willing to take a look at the database an see if they can figure out what is wrong with it? if so please email me @ [email protected] and I wil email you the database to look at... its only about 2mb (no info is in it) thanks in advance to anyone willing to help.
  • 0

#12
Hai Mac

Hai Mac

    Member

  • Member
  • PipPipPip
  • 260 posts
That is really weird :whistling:. I am not sure if the problem is with VB or Access, maybe you should check the language settings of your Access file. This does not look like a VB problem...

btw, they'll remove your email...
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP