Opening forms with same ID no

G

Guest

Hello, I am trying to open a next form and pass the autCUST_NO and intROOM_NO to the new form. However, with the following code I get a data mismatch. Any idea what I am doing wrong

Private Sub Command2_Click(
On Error GoTo Err_Command2_Clic


Dim stDocName As Strin
Dim stLinkCriteria As Strin
Dim stLinkCriteria1 As Strin
Dim stLinkCriteria2 As Strin

stDocName = "frmWINDOWS
stLinkCriteria1 = "[autCUST_NO]=" & "'" & Me![autCUST_NO] & "'
stLinkCriteria2 = "[intROOM_NO]=" & "'" & Me![txtROOM_NO] & "'
stLinkCriteria = stLinkCriteria1 And stLinkCriteria

DoCmd.OpenForm stDocName, , , stLinkCriteri

Exit_Command2_Click
Exit Su

Err_Command2_Click
MsgBox Err.Descriptio
Resume Exit_Command2_Clic

Thanks
 
D

Dirk Goldgar

Biggles said:
Hello, I am trying to open a next form and pass the autCUST_NO and
intROOM_NO to the new form. However, with the following code I get a
data mismatch. Any idea what I am doing wrong?

Private Sub Command2_Click()
On Error GoTo Err_Command2_Click


Dim stDocName As String
Dim stLinkCriteria As String
Dim stLinkCriteria1 As String
Dim stLinkCriteria2 As String

stDocName = "frmWINDOWS"
stLinkCriteria1 = "[autCUST_NO]=" & "'" & Me![autCUST_NO] & "'"
stLinkCriteria2 = "[intROOM_NO]=" & "'" & Me![txtROOM_NO] & "'"
stLinkCriteria = stLinkCriteria1 And stLinkCriteria2

DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command2_Click:
Exit Sub

Err_Command2_Click:
MsgBox Err.Description
Resume Exit_Command2_Click

Thanks

There are two potential problems. First, if your fields autCUST_NO and
intROOM_NO are numeric types, as their names suggest, then you shouldn't
be wrapping the embedded values in quotes, and these lines:
stLinkCriteria1 = "[autCUST_NO]=" & "'" & Me![autCUST_NO] & "'"
stLinkCriteria2 = "[intROOM_NO]=" & "'" & Me![txtROOM_NO] & "'"

should be like this:

stLinkCriteria1 = "[autCUST_NO]=" & Me![autCUST_NO]
stLinkCriteria2 = "[intROOM_NO]=" & Me![txtROOM_NO]

Ignore this correction if these are really text fields.

Second, you are combining the two subcriteria incorrectly. Change this:
stLinkCriteria = stLinkCriteria1 And stLinkCriteria2

to this:

stLinkCriteria = stLinkCriteria1 & " And " & stLinkCriteria2

Now, this won't exactly *pass* the criteria string to the new form, as
you said; it will *apply* the criteria to the form as a filter. If
that's what you intended, you should be all set.
 
B

Biggles

Dirk

Thank you for the advice. I knew one of the problems was
that one of the fields was numeric (the "aut" was a number
in the past, but changed now). However, I did not know
about the joining of the two filters. I think there are
too many languages going on, I am primarily an ACL power
user.

Sean
 

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

Type Mismatch 2
open form multiple criteria 3
Help with a filter when opening a form 4
Listbox 4
Code for closing Form 1
stLinkCriteria 2
Listbox to open a form (primary key text) 2
open in datasheet view 1

Top