Assistance needed with programming !!

A

Anonymous

Hi,

Who can tell me what goes wrong in the following code ?
I am trying to program a check (comparison of data coming
from two different tables, of which one is linked) which
has to be performed when the NextButton is clicked, but
it's not working yet. I am new to this programming thing,
so any help is appreciated !


Private Sub Next_Click()
On Error GoTo Err_Next_Click

Dim stDocName As String
Dim stLinkCriteria As String

If [PatientLinked]![PATIENTID] <> [Patient]!
[PATIENTID] Then

MsgBox "PatienID is incorrect"
DoCmd.Close

Else

stDocName = "Subject number"
DoCmd.OpenForm stDocName, , , stLinkCriteria, , ,
Me.Name
Me.Visible = False

End If
End If

Exit_Next_Click:
Exit Sub

Err_Next_Click:
MsgBox Err.Description
Resume Exit_Next_Click

End Sub
 
G

Guest

hi,
what is the code doing/not doing?
what is stdocname?
what is stlinkcriteria?
stdocname should be the name of the form. if not problem.
you set stlinkcriteria as a dimention but did not list any
criteria??????
The me.name is in the slot for the opening arguments????

docmd.openform "formname", accnormal
 
J

John Pritchard

Hi,

If you're trying to check data visible in two open forms
you need something like this:-

Private Sub Check_then_Next_Click()

MsgBox Forms![FORM1].[PatientID_Table1]
MsgBox Forms![FORM2].[PatientID_Table2]

If Forms![FORM1].[PatientID_Table1] <> Forms![FORM2].
[PatientID_Table2] Then

MsgBox "PatientIDs are different"

Else

DoCmd.GoToRecord , , acNext

End If


End Sub

The msgbox part isn't necessary in the final version but
it's good to use something like this to see what Access
is comparing.

However, I suspect that you may want to see if the data
in one table is actually present in the second. In this
case you'll need to use Dlookup. Check the way this works
in the VBA help - the example there will give you the
idea.

OK here's a piece of code to do that to get you
started ...


Private Sub Check_then_Next_Click()


Dim found As String

found = Nz(DLookup
("PatientID_Table2", "Table2", "PatientID_Table2 = '" _
& Forms![FORM1].[PatientID_Table1]
& "'"), "False")

If found <> "false" Then
MsgBox "Patient exists in table2"
DoCmd.GoToRecord , , acNext

Else

MsgBox "Patient does'nt exist in table2"

End If


End Sub

Good Luck !!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top