From Dialog, Find record, If No Match then New Record

D

DeDBlanK

Hi,
I have to make a entry form for people that are not tech savy.
The route I am taking is to use a dialog with selectable parameters on
it. When the user clicks the button, I want the form to search for
the criteria from a table. If the criteria matches, open entry form
with that record. If there is no match, then open the entry form and
automatically input the search parameters.
Still new at VBA and recordsets with DAO.
Here is the code for the button on the dialog so far:
*************************CODE**************************
Private Sub cmdFindAdd_Click()
Dim strSQL As String
Dim dtmDate As Date
Dim lngLine As Long
Dim lngShift As Long
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim blnFound As Boolean
Dim fldItem As DAO.Field

'Set bolean to false, used for verfying if record is found
blnFound = False
'If any criteria is missing end Sub
If Me.cmbDate = "" Or Me.cmbLine = "" Or Me.cmbShift = "" Then
Exit Sub
Set db = CurrentDb()

Set rs = New DAO.Recordset
Set strSQL = "SELECT * FROM tblProductionDate WHERE lngLineId = "
& Me.cmbLine & ", lngShift = " & Me.cmbShift & ", dtmDate = " &
Me.cmbDate & ";"
rs.OpenRecordset strSQL

With rstStoreItems
While Not .EOF
************************END CODE************************************
That's where I am stuck. Not quite sure where to go or if what I have
will even work. Looked around the web for something like what I am
asking, but really couldn't find a lot to show me how to call a
recordset from another table and then pull the Primary key over to the
entry form.
However, I think I could handle the code for inputting the parameter
data to the entry form on new record.
Something like:
Docmd.openform frmProdMain,,,NewRecord
dtmDate.value=cmbDate, lngLine.value=cmbLine,
lngShift.value=cmbShift ???
Guess my brain is just not working today =(
If anyone knows how I can accomplish this or has a better idea, I
would greatly appreciate it.
Thanks!
 
S

Steve Sanford

This is untested code.....

See if this helps you:

(watch for line wrap)

'*************************CODE**************************
'requires a reference set for Microsoft DAO 3.x Object Library
Private Sub cmdFindAdd_Click()
On Error GoTo HandleError
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String


'all three criteria required
'If any criteria is missing, say so and exit Sub
If Nz(Me.cmbDate, "") = "" Or Nz(Me.cmbLine, "") = "" Or Nz(Me.cmbShift,
"") = "" Then
MsgBox "parameters missing.! Enter all parameters"
Exit Sub
Else
Set db = CurrentDb()

'create SQL
strSQL = "SELECT lngLineId, lngShift, dtmDate FROM tblProductionDate"
strSQL = strSQL & " WHERE [lngLineId] = " & Me.cmbLine
strSQL = strSQL & " AND [lngShift] = " & Me.cmbShift
strSQL = strSQL & " AND [dtmDate] = #" & Me.cmbDate & "#;"

'open recordset
Set rs = db.OpenRecordset(strSQL)

'check for records
If rs.BOF And rs.EOF Then
MsgBox "No records found!!"

'open form in add mode
DoCmd.OpenForm "frmProdMain", , , , acFormAdd

Forms!frmProdMain.dtmDate = Me.cmbDate
Forms!frmProdMain.lngLine = Me.cmbLine
Forms!frmProdMain.lngShift = Me.cmbShift

Else
rs.MoveLast
rs.MoveFirst

'--- How many records for the criteria specified---
If rs.RecordCount = 1 Then
MsgBox rs.RecordCount & " record found"
Else
MsgBox rs.RecordCount & " records found"
End If
'------------------------

'open form to first record with [ponumber]
DoCmd.OpenForm "frmProdMain", , , "[ponumber] = " & Me.[ponumber]

End If
End If


HandleError_Exit:
On Error Resume Next

'clean up
rs.Close
Set rs = Nothing
Set db = Nothing
Exit Sub

HandleError:
MsgBox Err.Number & " - " & Err.Description
Resume HandleError_Exit
End Sub
'*************END CODE****************

HTH
 
D

DeDBlanK

This is untested code.....

See if this helps you:

(watch for line wrap)

'*************************CODE**************************
'requires a reference set for Microsoft DAO 3.x Object Library
Private Sub cmdFindAdd_Click()
   On Error GoTo HandleError
   Dim db As DAO.Database
   Dim rs As DAO.Recordset
   Dim strSQL As String

   'all three criteria required
   'If any criteria is missing, say so and exit Sub
   If Nz(Me.cmbDate, "") = "" Or Nz(Me.cmbLine, "") = "" Or Nz(Me.cmbShift,
"") = "" Then
      MsgBox "parameters missing.! Enter all parameters"
      Exit Sub
   Else
      Set db = CurrentDb()

      'create SQL
      strSQL = "SELECT lngLineId, lngShift, dtmDate FROM tblProductionDate"
      strSQL = strSQL & " WHERE [lngLineId] = " & Me.cmbLine
      strSQL = strSQL & " AND [lngShift] = " & Me.cmbShift
      strSQL = strSQL & " AND [dtmDate] = #" & Me.cmbDate & "#;"

      'open recordset
      Set rs = db.OpenRecordset(strSQL)

      'check for records
      If rs.BOF And rs.EOF Then
         MsgBox "No records found!!"

         'open form in add mode
         DoCmd.OpenForm "frmProdMain", , , , acFormAdd

         Forms!frmProdMain.dtmDate = Me.cmbDate
         Forms!frmProdMain.lngLine = Me.cmbLine
         Forms!frmProdMain.lngShift = Me.cmbShift

      Else
         rs.MoveLast
         rs.MoveFirst

         '--- How many records for the criteria specified---
         If rs.RecordCount = 1 Then
            MsgBox rs.RecordCount & " record found"
         Else
            MsgBox rs.RecordCount & " records found"
         End If
         '------------------------

         'open form to first record with [ponumber]
         DoCmd.OpenForm "frmProdMain", , , "[ponumber] = " & Me.[ponumber]

      End If
   End If

HandleError_Exit:
   On Error Resume Next

   'clean up
   rs.Close
   Set rs = Nothing
   Set db = Nothing
   Exit Sub

HandleError:
   MsgBox Err.Number & " - " & Err.Description
   Resume HandleError_Exit
End Sub
'*************END CODE****************

HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)



DeDBlanK said:
Hi,
I have to make a entry form for people that are not tech savy.
The route I am taking is to use a dialog with selectable parameters on
it.  When the user clicks the button, I want the form to search for
the criteria from a table.  If the criteria matches, open entry form
with that record.  If there is no match, then open the entry form and
automatically input the search parameters.
Still new at VBA and recordsets with DAO.
Here is the code for the button on the dialog so far:
*************************CODE**************************
Private Sub cmdFindAdd_Click()
    Dim strSQL As String
    Dim dtmDate As Date
    Dim lngLine As Long
    Dim lngShift As Long
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim blnFound As Boolean
    Dim fldItem As DAO.Field
    'Set bolean to false, used for verfying if record is found
    blnFound = False
    'If any criteria is missing end Sub
    If Me.cmbDate = "" Or Me.cmbLine = "" Or Me.cmbShift = "" Then
Exit Sub
    Set db = CurrentDb()
    Set rs = New DAO.Recordset
    Set strSQL = "SELECT * FROM tblProductionDate WHERE lngLineId = "
& Me.cmbLine & ", lngShift = " & Me.cmbShift & ", dtmDate = " &
Me.cmbDate & ";"
    rs.OpenRecordset strSQL
    With rstStoreItems
        While Not .EOF
************************END CODE************************************
That's where I am stuck.  Not quite sure where to go or if what I have
will even work.  Looked around the web for something like what I am
asking, but really couldn't find a lot to show me how to call a
recordset from another table and then pull the Primary key over to the
entry form.
However, I think I could handle the code for inputting the parameter
data to the entry form on new record.
Something like:
Docmd.openform frmProdMain,,,NewRecord
dtmDate.value=cmbDate, lngLine.value=cmbLine,
lngShift.value=cmbShift    ???
Guess my brain is just not working today =(
If anyone knows how I can accomplish this or has a better idea, I
would greatly appreciate it.
Thanks!- Hide quoted text -

- Show quoted text -

Mr. Sanford,

Thank you for the code. I actually started rewritting it and was
about to where you have it.

Couple of question though:

Under the line for

'open form to first record with [ponumber]
DoCmd.OpenForm "frmProdMain", , , "[ponumber] = " & Me.
[ponumber]

Where is the call out for the ponumber
(BTW, I didn't include this data, but it's actually [lngProdDateId]
which is the primary key for tblProductionDate which the frmProdMain
is bound to.)
That's where I am stuck now with the whole code.
I not quite sure how to pull the primary key from the recordset when
called from the strSQL, and then set that to the line where you have
the DoCmd.OpenForm "frmProdMain", , , "[ponumber] = " & Me.[ponumber]

Also, for the check records, isn't possible to use

If rs.NoMatch then
MsgBox "No Records Found!!"

Or is there a reason not to use NoMatch?

Thanks,
DeDBlanK
 
D

DeDBlanK

Sorry Double Post, but Read this one!!!!

Mr. Sanford,

Thank you for the code. I actually started rewritting it and was
about to where you have it.
One thing that I don't know if I made apparent. The dialog
(dlgFindAddReport) is actually an unbound form with combo boxes on it
with a giant button that run this code. So calling anything other
than the combo boxes won't amount to much. My bad.

I had a couple of question on the code though:

For the check records, isn't possible to use
------------------------------------------------------------------
If rs.NoMatch then
MsgBox "No Records Found!!"

Or is there a reason not to use NoMatch?

-------------------------------------------------------------------
Under the line for

'open form to first record with [ponumber]
DoCmd.OpenForm "frmProdMain", , , "[ponumber] = " & Me.
[ponumber]

Where is the call out for the ponumber
(BTW, I didn't include this data, but it's actually [lngProdDateId]
which is the primary key for tblProductionDate which the frmProdMain
is bound to.)
That's where I am stuck now with the whole code.
I not quite sure how to pull the primary key from the recordset when
called from the strSQL, and then set that to the line where you have
the DoCmd.OpenForm "frmProdMain", , , "[ponumber] = " & Me.[ponumber]
Do I need just need to add the field into the strSQL for the
lngProdDateId?
-----------------------------------------------------------------------
Thanks,
DeDBlanK
This is untested code.....
See if this helps you:
(watch for line wrap)
'*************************CODE**************************
'requires a reference set for Microsoft DAO 3.x Object Library
Private Sub cmdFindAdd_Click()
   On Error GoTo HandleError
   Dim db As DAO.Database
   Dim rs As DAO.Recordset
   Dim strSQL As String
   'all three criteria required
   'If any criteria is missing, say so and exit Sub
   If Nz(Me.cmbDate, "") = "" Or Nz(Me.cmbLine, "") = "" Or Nz(Me.cmbShift,
"") = "" Then
      MsgBox "parameters missing.! Enter all parameters"
      Exit Sub
   Else
      Set db = CurrentDb()
      'create SQL
      strSQL = "SELECT lngLineId, lngShift, dtmDate FROM tblProductionDate"
      strSQL = strSQL & " WHERE [lngLineId] = " & Me.cmbLine
      strSQL = strSQL & " AND [lngShift] = " & Me.cmbShift
      strSQL = strSQL & " AND [dtmDate] = #" & Me.cmbDate & "#;"
      'open recordset
      Set rs = db.OpenRecordset(strSQL)
      'check for records
      If rs.BOF And rs.EOF Then
         MsgBox "No records found!!"
         'open form in add mode
         DoCmd.OpenForm "frmProdMain", , , , acFormAdd
         Forms!frmProdMain.dtmDate = Me.cmbDate
         Forms!frmProdMain.lngLine = Me.cmbLine
         Forms!frmProdMain.lngShift = Me.cmbShift
      Else
         rs.MoveLast
         rs.MoveFirst
         '--- How many records for the criteria specified---
         If rs.RecordCount = 1 Then
            MsgBox rs.RecordCount & " record found"
         Else
            MsgBox rs.RecordCount & " records found"
         End If
         '------------------------
         'open form to first record with [ponumber]
         DoCmd.OpenForm "frmProdMain", , , "[ponumber] = " &Me.[ponumber]
      End If
   End If
HandleError_Exit:
   On Error Resume Next
   'clean up
   rs.Close
   Set rs = Nothing
   Set db = Nothing
   Exit Sub
HandleError:
   MsgBox Err.Number & " - " & Err.Description
   Resume HandleError_Exit
End Sub
'*************END CODE****************
- Show quoted text -

Mr. Sanford,

Thank you for the code.  I actually started rewritting it and was
about to where you have it.

Couple of question though:

Under the line for

'open form to first record with [ponumber]
         DoCmd.OpenForm "frmProdMain", , , "[ponumber] = " & Me.
[ponumber]

Where is the call out for the ponumber
(BTW, I didn't include this data, but it's actually [lngProdDateId]
which is the primary key for tblProductionDate which the frmProdMain
is bound to.)
That's where I am stuck now with the whole code.
I not quite sure how to pull the primary key from the recordset when
called from the strSQL, and then set that to the line where you have
the DoCmd.OpenForm "frmProdMain", , , "[ponumber] = " & Me.[ponumber]

Also, for the check records, isn't possible to use

If rs.NoMatch then
     MsgBox "No Records Found!!"

Or is there a reason not to use NoMatch?

Thanks,
DeDBlanK- Hide quoted text -

- Show quoted text -
 
D

DeDBlanK

Ran the Code and I get an error

2465-Application-defined or object-defined error

It's happening at:
DoCmd.OpenForm "frmProdMain", , , , acFormAdd

Forms!frmProdMain.dtmDate.Value = me.txtDate
Forms!frmProdMain.lngLine.Value = me.cmbLine
Forms!frmProdMain.lngShift.Value = me.cmbShift

I've tried using the long definition, Forms!dlgFindAddReport!txtDate
to no avail.

Also getting the same error number for a found record:
2465 - Access can't find the field '|" referred to in your expression

This is probably from the same thing I stated in my previous post
about not being bound to anything.
Sorry Double Post, but Read this one!!!!

Mr. Sanford,

Thank you for the code.  I actually started rewritting it and was
about to where you have it.
One thing that I don't know if I made apparent.  The dialog
(dlgFindAddReport) is actually an unbound form with combo boxes on it
with a giant button that run this code.  So calling anything other
than the combo boxes won't amount to much. My bad.

I had a couple of question on the code though:

For the check records, isn't possible to use
------------------------------------------------------------------
If rs.NoMatch then
     MsgBox "No Records Found!!"

Or is there a reason not to use NoMatch?

-------------------------------------------------------------------
Under the line for

'open form to first record with [ponumber]
        DoCmd.OpenForm "frmProdMain", , , "[ponumber] = " & Me.
[ponumber]

Where is the call out for the ponumber
(BTW, I didn't include this data, but it's actually [lngProdDateId]
which is the primary key for tblProductionDate which the frmProdMain
is bound to.)
That's where I am stuck now with the whole code.
I not quite sure how to pull the primary key from the recordset when
called from the strSQL, and then set that to the line where you have
the DoCmd.OpenForm "frmProdMain", , , "[ponumber] = " & Me.[ponumber]
Do I need just need to add the field into the strSQL for the
lngProdDateId?
-----------------------------------------------------------------------
Thanks,
DeDBlanK


On May 6, 11:59 am, Steve Sanford <limbim53 at yahoo dot com> wrote:
This is untested code.....
See if this helps you:
(watch for line wrap)
'*************************CODE**************************
'requires a reference set for Microsoft DAO 3.x Object Library
Private Sub cmdFindAdd_Click()
   On Error GoTo HandleError
   Dim db As DAO.Database
   Dim rs As DAO.Recordset
   Dim strSQL As String
   'all three criteria required
   'If any criteria is missing, say so and exit Sub
   If Nz(Me.cmbDate, "") = "" Or Nz(Me.cmbLine, "") = "" Or Nz(Me.cmbShift,
"") = "" Then
      MsgBox "parameters missing.! Enter all parameters"
      Exit Sub
   Else
      Set db = CurrentDb()
      'create SQL
      strSQL = "SELECT lngLineId, lngShift, dtmDate FROM tblProductionDate"
      strSQL = strSQL & " WHERE [lngLineId] = " & Me.cmbLine
      strSQL = strSQL & " AND [lngShift] = " & Me.cmbShift
      strSQL = strSQL & " AND [dtmDate] = #" & Me.cmbDate & "#;"
      'open recordset
      Set rs = db.OpenRecordset(strSQL)
      'check for records
      If rs.BOF And rs.EOF Then
         MsgBox "No records found!!"
         'open form in add mode
         DoCmd.OpenForm "frmProdMain", , , , acFormAdd
         Forms!frmProdMain.dtmDate = Me.cmbDate
         Forms!frmProdMain.lngLine = Me.cmbLine
         Forms!frmProdMain.lngShift = Me.cmbShift
      Else
         rs.MoveLast
         rs.MoveFirst
         '--- How many records for the criteria specified---
         If rs.RecordCount = 1 Then
            MsgBox rs.RecordCount & " record found"
         Else
            MsgBox rs.RecordCount & " records found"
         End If
         '------------------------
         'open form to first record with [ponumber]
         DoCmd.OpenForm "frmProdMain", , , "[ponumber] = "& Me.[ponumber]
      End If
   End If
HandleError_Exit:
   On Error Resume Next
   'clean up
   rs.Close
   Set rs = Nothing
   Set db = Nothing
   Exit Sub
HandleError:
   MsgBox Err.Number & " - " & Err.Description
   Resume HandleError_Exit
End Sub
'*************END CODE****************
HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)
:
Hi,
I have to make a entry form for people that are not tech savy.
The route I am taking is to use a dialog with selectable parameters on
it.  When the user clicks the button, I want the form to search for
the criteria from a table.  If the criteria matches, open entry form
with that record.  If there is no match, then open the entry form and
automatically input the search parameters.
Still new at VBA and recordsets with DAO.
Here is the code for the button on the dialog so far:
*************************CODE**************************
Private Sub cmdFindAdd_Click()
    Dim strSQL As String
    Dim dtmDate As Date
    Dim lngLine As Long
    Dim lngShift As Long
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim blnFound As Boolean
    Dim fldItem As DAO.Field
    'Set bolean to false, used for verfying if record is found
    blnFound = False
    'If any criteria is missing end Sub
    If Me.cmbDate = "" Or Me.cmbLine = "" Or Me.cmbShift ="" Then
Exit Sub
    Set db = CurrentDb()
    Set rs = New DAO.Recordset
    Set strSQL = "SELECT * FROM tblProductionDate WHERE lngLineId = "
& Me.cmbLine & ", lngShift = " & Me.cmbShift & ", dtmDate = " &
Me.cmbDate & ";"
    rs.OpenRecordset strSQL
    With rstStoreItems
        While Not .EOF
************************END CODE************************************
That's where I am stuck.  Not quite sure where to go or if what I have
will even work.  Looked around the web for something like what I am
asking, but really couldn't find a lot to show me how to call a
recordset from another table and then pull the Primary key over to the
entry form.
However, I think I could handle the code for inputting the parameter
data to the entry form on new record.
Something like:
Docmd.openform frmProdMain,,,NewRecord
dtmDate.value=cmbDate, lngLine.value=cmbLine,
lngShift.value=cmbShift    ???
Guess my brain is just not working today =(
If anyone knows how I can accomplish this or has a better idea, I
would greatly appreciate it.
Thanks!- Hide quoted text -
- Show quoted text -
Mr. Sanford,
Thank you for the code.  I actually started rewritting it and was
about to where you have it.
Couple of question though:
Under the line for
'open form to first record with [ponumber]
         DoCmd.OpenForm "frmProdMain", , , "[ponumber] = " &Me.
[ponumber]
Where is the call out for the ponumber
(BTW, I didn't include this data, but it's actually [lngProdDateId]
which is the primary key for tblProductionDate which the frmProdMain
is bound to.)
That's where I am stuck now with the whole code.
I not quite sure how to pull the primary key from the recordset when
called from the strSQL, and then set that to the line where you have
the DoCmd.OpenForm "frmProdMain", , , "[ponumber] = " & Me.[ponumber]
Also, for the check records, isn't possible to use
If rs.NoMatch then
     MsgBox "No Records Found!!"
Or is there a reason not to use NoMatch?
Thanks,
DeDBlanK- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -
 
S

Steve Sanford

For the check records, isn't possible to use
------------------------------------------------------------------
If rs.NoMatch then
MsgBox "No Records Found!!"

Or is there a reason not to use NoMatch?

-------------------------------------------------------------------

If a recordset is opened without using a "Where" clause, all records are
returned. To find a specific record or records, you could use the .FindFirst
method. The NoMatch property is used to determine whether a Find/Seek
operation has succeeded.

If you use criteria (ie, a Where clause) when a recordset is opened, only
the records that match the criteria are returned. Opening a record does not
ahave a "NoMatch" property.

Under the line for

'open form to first record with [ponumber]
DoCmd.OpenForm "frmProdMain", , , "[ponumber] = " & Me.
[ponumber]

Where is the call out for the ponumber
(BTW, I didn't include this data, but it's actually [lngProdDateId]
which is the primary key for tblProductionDate which the frmProdMain
is bound to.)

From your question, I didn't know your form names or field names, so I took
a guess.

Opening a recordset using "SELECT * FROM..." is slower and unneeded,
especially when the only field you need from the table is the PK. So I would
use:

strSQL = "SELECT lngProdDateId FROM tblProductionDate"
strSQL = strSQL & " WHERE [lngLineId] = " & Me.cmbLine
strSQL = strSQL & " AND [lngShift] = " & Me.cmbShift
strSQL = strSQL & " AND [dtmDate] = #" & Me.cmbDate & "#;"
That's where I am stuck now with the whole code.
I not quite sure how to pull the primary key from the recordset when
called from the strSQL, and then set that to the line where you have
the DoCmd.OpenForm "frmProdMain", , , "[ponumber] = " & Me.[ponumber]

Try:

DoCmd.OpenForm "frmProdMain", , , "[lngProdDateId] = " & rs!lngProdDateId


HTH
 
S

Steve Sanford

With the new info you provided, I made a table and a couple of forms. Since I
can't see the structure of your mdb (tables & forms), this might still have
errors.

First, from the main database window, select TOOLS/OPTIONS
Click on the "General" tab.
Uncheck both "Name Autocorrect" check boxes.

This is optional - Click on the FORMS/REPORTS
CHECK the "Always use event procedures"
Click OK

In the IDE, select TOOLS/OPTIONS
Every thing should be checked except the first check box "Auto syntax check"
Click OK

Paste in the following code. Then, in the menu bar, select DEBUG/COMPILE
Fix any errors.

'*******************CODE*************
Private Sub cmdFindAdd_Click()
On Error GoTo HandleError
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String


'all three criteria required
'If any criteria is missing, say so and exit Sub
If Nz(Me.txtDate, "") = "" Or Nz(Me.cmbLine, "") = "" Or Nz(Me.cmbShift,
"") = "" Then
MsgBox "parameters missing.! Enter all parameters"
Exit Sub
Else
Set db = CurrentDb()

'create SQL
strSQL = "SELECT lngProdDateId FROM tblProductionDate"
strSQL = strSQL & " WHERE [lngLineId] = " & Me.cmbLine
strSQL = strSQL & " AND [lngShift] = " & Me.cmbShift
strSQL = strSQL & " AND [dtmDate] = #" & Me.txtDate & "#;"

'open recordset
Set rs = db.OpenRecordset(strSQL)

'check for records
If rs.BOF And rs.EOF Then
MsgBox "No records found!!"

'open form in add mode
DoCmd.OpenForm "frmProdMain", , , , acFormAdd

Forms!frmProdMain.dtmDate = Me.txtDate
Forms!frmProdMain.lngLineID = Me.cmbLine
Forms!frmProdMain.lngShift = Me.cmbShift

Else
rs.MoveLast
rs.MoveFirst

'--- How many records for the criteria specified---
If rs.RecordCount = 1 Then
MsgBox rs.RecordCount & " record found"
Else
MsgBox rs.RecordCount & " records found"
End If
'------------------------

'open form to first record with [ponumber]
DoCmd.OpenForm "frmProdMain", , , "[lngProdDateId] = " &
rs!lngProdDateId

End If
End If


HandleError_Exit:
On Error Resume Next

'clean up
rs.Close
Set rs = Nothing
Set db = Nothing

'optional - close the form dlgFindAddReport
DoCmd.Close acForm, Me.Name

Exit Sub

HandleError:
MsgBox Err.Number & " - " & Err.Description
Resume HandleError_Exit
End Sub
'************************END CODE*************

This code compiles and run - for me - with my forms and table. Check field
and control names if you get errors. (and let me know :)

I added these two lines to close the form "dlgFindAddReport"

'optional - close the form dlgFindAddReport
DoCmd.Close acForm, Me.Name


HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


DeDBlanK said:
Ran the Code and I get an error

2465-Application-defined or object-defined error

It's happening at:
DoCmd.OpenForm "frmProdMain", , , , acFormAdd

Forms!frmProdMain.dtmDate.Value = me.txtDate
Forms!frmProdMain.lngLine.Value = me.cmbLine
Forms!frmProdMain.lngShift.Value = me.cmbShift

I've tried using the long definition, Forms!dlgFindAddReport!txtDate
to no avail.

Also getting the same error number for a found record:
2465 - Access can't find the field '|" referred to in your expression

This is probably from the same thing I stated in my previous post
about not being bound to anything.
Sorry Double Post, but Read this one!!!!

Mr. Sanford,

Thank you for the code. I actually started rewritting it and was
about to where you have it.
One thing that I don't know if I made apparent. The dialog
(dlgFindAddReport) is actually an unbound form with combo boxes on it
with a giant button that run this code. So calling anything other
than the combo boxes won't amount to much. My bad.

I had a couple of question on the code though:

For the check records, isn't possible to use
------------------------------------------------------------------
If rs.NoMatch then
MsgBox "No Records Found!!"

Or is there a reason not to use NoMatch?

-------------------------------------------------------------------
Under the line for

'open form to first record with [ponumber]
DoCmd.OpenForm "frmProdMain", , , "[ponumber] = " & Me.
[ponumber]

Where is the call out for the ponumber
(BTW, I didn't include this data, but it's actually [lngProdDateId]
which is the primary key for tblProductionDate which the frmProdMain
is bound to.)
That's where I am stuck now with the whole code.
I not quite sure how to pull the primary key from the recordset when
called from the strSQL, and then set that to the line where you have
the DoCmd.OpenForm "frmProdMain", , , "[ponumber] = " & Me.[ponumber]
Do I need just need to add the field into the strSQL for the
lngProdDateId?
-----------------------------------------------------------------------
Thanks,
DeDBlanK


On May 6, 11:59 am, Steve Sanford <limbim53 at yahoo dot com> wrote:
This is untested code.....
See if this helps you:
(watch for line wrap)
'*************************CODE**************************
'requires a reference set for Microsoft DAO 3.x Object Library
Private Sub cmdFindAdd_Click()
On Error GoTo HandleError
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
'all three criteria required
'If any criteria is missing, say so and exit Sub
If Nz(Me.cmbDate, "") = "" Or Nz(Me.cmbLine, "") = "" Or Nz(Me.cmbShift,
"") = "" Then
MsgBox "parameters missing.! Enter all parameters"
Exit Sub
Else
Set db = CurrentDb()
'create SQL
strSQL = "SELECT lngLineId, lngShift, dtmDate FROM tblProductionDate"
strSQL = strSQL & " WHERE [lngLineId] = " & Me.cmbLine
strSQL = strSQL & " AND [lngShift] = " & Me.cmbShift
strSQL = strSQL & " AND [dtmDate] = #" & Me.cmbDate & "#;"
'open recordset
Set rs = db.OpenRecordset(strSQL)
'check for records
If rs.BOF And rs.EOF Then
MsgBox "No records found!!"
'open form in add mode
DoCmd.OpenForm "frmProdMain", , , , acFormAdd
Forms!frmProdMain.dtmDate = Me.cmbDate
Forms!frmProdMain.lngLine = Me.cmbLine
Forms!frmProdMain.lngShift = Me.cmbShift

'--- How many records for the criteria specified---
If rs.RecordCount = 1 Then
MsgBox rs.RecordCount & " record found"
Else
MsgBox rs.RecordCount & " records found"
End If
'------------------------
'open form to first record with [ponumber]
DoCmd.OpenForm "frmProdMain", , , "[ponumber] = " & Me.[ponumber]
End If
End If
HandleError_Exit:
On Error Resume Next
'clean up
rs.Close
Set rs = Nothing
Set db = Nothing
Exit Sub
HandleError:
MsgBox Err.Number & " - " & Err.Description
Resume HandleError_Exit
End Sub
'*************END CODE****************
:
Hi,
I have to make a entry form for people that are not tech savy.
The route I am taking is to use a dialog with selectable parameters on
it. When the user clicks the button, I want the form to search for
the criteria from a table. If the criteria matches, open entry form
with that record. If there is no match, then open the entry form and
automatically input the search parameters.
Still new at VBA and recordsets with DAO.
Here is the code for the button on the dialog so far:
*************************CODE**************************
Private Sub cmdFindAdd_Click()
Dim strSQL As String
Dim dtmDate As Date
Dim lngLine As Long
Dim lngShift As Long
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim blnFound As Boolean
Dim fldItem As DAO.Field
'Set bolean to false, used for verfying if record is found
blnFound = False
'If any criteria is missing end Sub
If Me.cmbDate = "" Or Me.cmbLine = "" Or Me.cmbShift = "" Then
Exit Sub
Set db = CurrentDb()
Set rs = New DAO.Recordset
Set strSQL = "SELECT * FROM tblProductionDate WHERE lngLineId = "
& Me.cmbLine & ", lngShift = " & Me.cmbShift & ", dtmDate = " &
Me.cmbDate & ";"
rs.OpenRecordset strSQL
With rstStoreItems
While Not .EOF
************************END CODE************************************
That's where I am stuck. Not quite sure where to go or if what I have
will even work. Looked around the web for something like what I am
asking, but really couldn't find a lot to show me how to call a
recordset from another table and then pull the Primary key over to the
entry form.
However, I think I could handle the code for inputting the parameter
data to the entry form on new record.
Something like:
Docmd.openform frmProdMain,,,NewRecord
dtmDate.value=cmbDate, lngLine.value=cmbLine,
lngShift.value=cmbShift ???
Guess my brain is just not working today =(
If anyone knows how I can accomplish this or has a better idea, I
would greatly appreciate it.
Thanks!- Hide quoted text -
- Show quoted text -
Mr. Sanford,
Thank you for the code. I actually started rewritting it and was
about to where you have it.
Couple of question though:
Under the line for
'open form to first record with [ponumber]
DoCmd.OpenForm "frmProdMain", , , "[ponumber] = " & Me.
[ponumber]
Where is the call out for the ponumber
(BTW, I didn't include this data, but it's actually [lngProdDateId]
which is the primary key for tblProductionDate which the frmProdMain
is bound to.)
That's where I am stuck now with the whole code.
I not quite sure how to pull the primary key from the recordset when
called from the strSQL, and then set that to the line where you have
the DoCmd.OpenForm "frmProdMain", , , "[ponumber] = " & Me.[ponumber]
Also, for the check records, isn't possible to use
If rs.NoMatch then
MsgBox "No Records Found!!"
Or is there a reason not to use NoMatch?
Thanks,
DeDBlanK- Hide quoted text -
- Show quoted text -- Hide quoted text -

- Show quoted text -
 
D

DeDBlanK

On May 6, 6:56 pm, Steve Sanford <limbim53 at yahoo dot com> wrote:

Thank you again for all your help. I really do appreciate it.
I figured out my issue, I'm such an idiot.
The whole error was due to me not typing the name correctly for the
field.

Forms!frmProdMain.dtmDate = Me.txtDate
Forms!frmProdMain.lngLineID = Me.cmbLine <-This one
Forms!frmProdMain.lngShift = Me.cmbShift

On my code for some reason I didn't type the Id at the end of
lngLineId.

Again I can't thank you enough. I'm still a Noob when it come to VBA,
but the books are helping.
Thanks,
DeDBlanK

With the new info you provided, I made a table and a couple of forms. Since I
can't see the structure of your mdb (tables & forms), this might still have
errors.

First, from the main database window, select TOOLS/OPTIONS
Click on the "General" tab.
Uncheck both "Name Autocorrect" check boxes.

This is optional - Click on the FORMS/REPORTS
CHECK the "Always use event procedures"
Click OK

In the IDE, select TOOLS/OPTIONS
Every thing should be checked except the first check box "Auto syntax check"
Click OK

Paste in the following code. Then, in the menu bar, select DEBUG/COMPILE
Fix any errors.

'*******************CODE*************
Private Sub cmdFindAdd_Click()
   On Error GoTo HandleError
   Dim db As DAO.Database
   Dim rs As DAO.Recordset
   Dim strSQL As String

   'all three criteria required
   'If any criteria is missing, say so and exit Sub
   If Nz(Me.txtDate, "") = "" Or Nz(Me.cmbLine, "") = "" Or Nz(Me.cmbShift,
"") = "" Then
      MsgBox "parameters missing.! Enter all parameters"
      Exit Sub
   Else
      Set db = CurrentDb()

      'create SQL
      strSQL = "SELECT lngProdDateId FROM tblProductionDate"
      strSQL = strSQL & " WHERE [lngLineId] = " & Me.cmbLine
      strSQL = strSQL & " AND [lngShift] = " & Me.cmbShift
      strSQL = strSQL & " AND [dtmDate] = #" & Me.txtDate & "#;"

      'open recordset
      Set rs = db.OpenRecordset(strSQL)

      'check for records
      If rs.BOF And rs.EOF Then
         MsgBox "No records found!!"

         'open form in add mode
         DoCmd.OpenForm "frmProdMain", , , , acFormAdd

         Forms!frmProdMain.dtmDate = Me.txtDate
         Forms!frmProdMain.lngLineID = Me.cmbLine
         Forms!frmProdMain.lngShift = Me.cmbShift

      Else
         rs.MoveLast
         rs.MoveFirst

         '--- How many records for the criteria specified---
         If rs.RecordCount = 1 Then
            MsgBox rs.RecordCount & " record found"
         Else
            MsgBox rs.RecordCount & " records found"
         End If
         '------------------------

         'open form to first record with [ponumber]
         DoCmd.OpenForm "frmProdMain", , , "[lngProdDateId] = " &
rs!lngProdDateId

      End If
   End If

HandleError_Exit:
   On Error Resume Next

   'clean up
   rs.Close
   Set rs = Nothing
   Set db = Nothing

   'optional - close the form dlgFindAddReport
   DoCmd.Close acForm, Me.Name

   Exit Sub

HandleError:
   MsgBox Err.Number & " - " & Err.Description
   Resume HandleError_Exit
End Sub
'************************END CODE*************

This code compiles and run - for me - with my forms and table. Check field
and control names if you get errors. (and let me know  :)

I added these two lines to close the form "dlgFindAddReport"

   'optional - close the form dlgFindAddReport
   DoCmd.Close acForm, Me.Name

HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)



DeDBlanK said:
Ran the Code and I get an error
2465-Application-defined or object-defined error
It's happening at:
DoCmd.OpenForm "frmProdMain", , , , acFormAdd
         Forms!frmProdMain.dtmDate.Value = me.txtDate
         Forms!frmProdMain.lngLine.Value = me.cmbLine
         Forms!frmProdMain.lngShift.Value = me.cmbShift
I've tried using the long definition, Forms!dlgFindAddReport!txtDate
to no avail.
Also getting the same error number for a found record:
2465 - Access can't find the field '|" referred to in your expression
This is probably from the same thing I stated in my previous post
about not being bound to anything.
Sorry Double Post, but Read this one!!!!
Mr. Sanford,
Thank you for the code.  I actually started rewritting it and was
about to where you have it.
One thing that I don't know if I made apparent.  The dialog
(dlgFindAddReport) is actually an unbound form with combo boxes on it
with a giant button that run this code.  So calling anything other
than the combo boxes won't amount to much. My bad.
I had a couple of question on the code though:
For the check records, isn't possible to use
------------------------------------------------------------------
If rs.NoMatch then
     MsgBox "No Records Found!!"
Or is there a reason not to use NoMatch?
-------------------------------------------------------------------
Under the line for
'open form to first record with [ponumber]
        DoCmd.OpenForm "frmProdMain", , , "[ponumber] = " & Me.
[ponumber]
Where is the call out for the ponumber
(BTW, I didn't include this data, but it's actually [lngProdDateId]
which is the primary key for tblProductionDate which the frmProdMain
is bound to.)
That's where I am stuck now with the whole code.
I not quite sure how to pull the primary key from the recordset when
called from the strSQL, and then set that to the line where you have
the DoCmd.OpenForm "frmProdMain", , , "[ponumber] = " & Me.[ponumber]
Do I need just need to add the field into the strSQL for the
lngProdDateId?
-----------------------------------------------------------------------
Thanks,
DeDBlanK
On May 6, 11:59 am, Steve Sanford <limbim53 at yahoo dot com> wrote:
This is untested code.....
See if this helps you:
(watch for line wrap)
'*************************CODE**************************
'requires a reference set for Microsoft DAO 3.x Object Library
Private Sub cmdFindAdd_Click()
   On Error GoTo HandleError
   Dim db As DAO.Database
   Dim rs As DAO.Recordset
   Dim strSQL As String
   'all three criteria required
   'If any criteria is missing, say so and exit Sub
   If Nz(Me.cmbDate, "") = "" Or Nz(Me.cmbLine, "") = "" Or Nz(Me.cmbShift,
"") = "" Then
      MsgBox "parameters missing.! Enter all parameters"
      Exit Sub
   Else
      Set db = CurrentDb()
      'create SQL
      strSQL = "SELECT lngLineId, lngShift, dtmDate FROM tblProductionDate"
      strSQL = strSQL & " WHERE [lngLineId] = " & Me.cmbLine
      strSQL = strSQL & " AND [lngShift] = " & Me.cmbShift
      strSQL = strSQL & " AND [dtmDate] = #" & Me.cmbDate & "#;"
      'open recordset
      Set rs = db.OpenRecordset(strSQL)
      'check for records
      If rs.BOF And rs.EOF Then
         MsgBox "No records found!!"
         'open form in add mode
         DoCmd.OpenForm "frmProdMain", , , , acFormAdd
         Forms!frmProdMain.dtmDate = Me.cmbDate
         Forms!frmProdMain.lngLine = Me.cmbLine
         Forms!frmProdMain.lngShift = Me.cmbShift
      Else
         rs.MoveLast
         rs.MoveFirst
         '--- How many records for the criteria specified---
         If rs.RecordCount = 1 Then
            MsgBox rs.RecordCount & " record found"
         Else
            MsgBox rs.RecordCount & " records found"
         End If
         '------------------------
         'open form to first record with [ponumber]
         DoCmd.OpenForm "frmProdMain", , , "[ponumber] = " & Me.[ponumber]
      End If
   End If
HandleError_Exit:
   On Error Resume Next
   'clean up
   rs.Close
   Set rs = Nothing
   Set db = Nothing
   Exit Sub
HandleError:
   MsgBox Err.Number & " - " & Err.Description
   Resume HandleError_Exit
End Sub
'*************END CODE****************
HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)
:
Hi,
I have to make a entry form for people that are not tech savy.
The route I am taking is to use a dialog with selectable parameters on
it.  When the user clicks the button, I want the form to search for
the criteria from a table.  If the criteria matches, open entry form
with that record.  If there is no match, then open the entry form and
automatically input the search parameters.
Still new at VBA and recordsets with DAO.
Here is the code for the button on the dialog so far:
*************************CODE**************************
Private Sub cmdFindAdd_Click()
    Dim strSQL As String
    Dim dtmDate As Date
    Dim lngLine As Long
    Dim lngShift As Long
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim blnFound As Boolean
    Dim fldItem As DAO.Field
    'Set bolean to false, used for verfying if record is found
    blnFound = False
    'If any criteria is missing end Sub
    If Me.cmbDate = "" Or Me.cmbLine = "" Or Me.cmbShift= "" Then
Exit Sub
    Set db = CurrentDb()
    Set rs = New DAO.Recordset
    Set strSQL = "SELECT * FROM tblProductionDate WHERE lngLineId = "
& Me.cmbLine & ", lngShift = " & Me.cmbShift & ", dtmDate = " &
Me.cmbDate & ";"
    rs.OpenRecordset strSQL
    With rstStoreItems
        While Not .EOF
************************END CODE************************************
That's where I am stuck.  Not quite sure where to go or if what I have
will even work.  Looked around the web for something

...

read more »- Hide quoted text -

- Show quoted text -
 
S

Steve Sanford

Glad it is working.

--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)


DeDBlanK said:
On May 6, 6:56 pm, Steve Sanford <limbim53 at yahoo dot com> wrote:

Thank you again for all your help. I really do appreciate it.
I figured out my issue, I'm such an idiot.
The whole error was due to me not typing the name correctly for the
field.

Forms!frmProdMain.dtmDate = Me.txtDate
Forms!frmProdMain.lngLineID = Me.cmbLine <-This one
Forms!frmProdMain.lngShift = Me.cmbShift

On my code for some reason I didn't type the Id at the end of
lngLineId.

Again I can't thank you enough. I'm still a Noob when it come to VBA,
but the books are helping.
Thanks,
DeDBlanK

With the new info you provided, I made a table and a couple of forms. Since I
can't see the structure of your mdb (tables & forms), this might still have
errors.

First, from the main database window, select TOOLS/OPTIONS
Click on the "General" tab.
Uncheck both "Name Autocorrect" check boxes.

This is optional - Click on the FORMS/REPORTS
CHECK the "Always use event procedures"
Click OK

In the IDE, select TOOLS/OPTIONS
Every thing should be checked except the first check box "Auto syntax check"
Click OK

Paste in the following code. Then, in the menu bar, select DEBUG/COMPILE
Fix any errors.

'*******************CODE*************
Private Sub cmdFindAdd_Click()
On Error GoTo HandleError
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String

'all three criteria required
'If any criteria is missing, say so and exit Sub
If Nz(Me.txtDate, "") = "" Or Nz(Me.cmbLine, "") = "" Or Nz(Me.cmbShift,
"") = "" Then
MsgBox "parameters missing.! Enter all parameters"
Exit Sub
Else
Set db = CurrentDb()

'create SQL
strSQL = "SELECT lngProdDateId FROM tblProductionDate"
strSQL = strSQL & " WHERE [lngLineId] = " & Me.cmbLine
strSQL = strSQL & " AND [lngShift] = " & Me.cmbShift
strSQL = strSQL & " AND [dtmDate] = #" & Me.txtDate & "#;"

'open recordset
Set rs = db.OpenRecordset(strSQL)

'check for records
If rs.BOF And rs.EOF Then
MsgBox "No records found!!"

'open form in add mode
DoCmd.OpenForm "frmProdMain", , , , acFormAdd

Forms!frmProdMain.dtmDate = Me.txtDate
Forms!frmProdMain.lngLineID = Me.cmbLine
Forms!frmProdMain.lngShift = Me.cmbShift

Else
rs.MoveLast
rs.MoveFirst

'--- How many records for the criteria specified---
If rs.RecordCount = 1 Then
MsgBox rs.RecordCount & " record found"
Else
MsgBox rs.RecordCount & " records found"
End If
'------------------------

'open form to first record with [ponumber]
DoCmd.OpenForm "frmProdMain", , , "[lngProdDateId] = " &
rs!lngProdDateId

End If
End If

HandleError_Exit:
On Error Resume Next

'clean up
rs.Close
Set rs = Nothing
Set db = Nothing

'optional - close the form dlgFindAddReport
DoCmd.Close acForm, Me.Name

Exit Sub

HandleError:
MsgBox Err.Number & " - " & Err.Description
Resume HandleError_Exit
End Sub
'************************END CODE*************

This code compiles and run - for me - with my forms and table. Check field
and control names if you get errors. (and let me know :)

I added these two lines to close the form "dlgFindAddReport"

'optional - close the form dlgFindAddReport
DoCmd.Close acForm, Me.Name

HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)



DeDBlanK said:
Ran the Code and I get an error
2465-Application-defined or object-defined error
It's happening at:
DoCmd.OpenForm "frmProdMain", , , , acFormAdd
Forms!frmProdMain.dtmDate.Value = me.txtDate
Forms!frmProdMain.lngLine.Value = me.cmbLine
Forms!frmProdMain.lngShift.Value = me.cmbShift
I've tried using the long definition, Forms!dlgFindAddReport!txtDate
to no avail.
Also getting the same error number for a found record:
2465 - Access can't find the field '|" referred to in your expression
This is probably from the same thing I stated in my previous post
about not being bound to anything.
Sorry Double Post, but Read this one!!!!
Mr. Sanford,
Thank you for the code. I actually started rewritting it and was
about to where you have it.
One thing that I don't know if I made apparent. The dialog
(dlgFindAddReport) is actually an unbound form with combo boxes on it
with a giant button that run this code. So calling anything other
than the combo boxes won't amount to much. My bad.
I had a couple of question on the code though:
For the check records, isn't possible to use
Or is there a reason not to use NoMatch?
'open form to first record with [ponumber]
DoCmd.OpenForm "frmProdMain", , , "[ponumber] = " & Me.
[ponumber]
Where is the call out for the ponumber
(BTW, I didn't include this data, but it's actually [lngProdDateId]
which is the primary key for tblProductionDate which the frmProdMain
is bound to.)
That's where I am stuck now with the whole code.
I not quite sure how to pull the primary key from the recordset when
called from the strSQL, and then set that to the line where you have
the DoCmd.OpenForm "frmProdMain", , , "[ponumber] = " & Me.[ponumber]
Do I need just need to add the field into the strSQL for the
lngProdDateId?
On May 6, 11:59 am, Steve Sanford <limbim53 at yahoo dot com> wrote:
This is untested code.....
See if this helps you:
(watch for line wrap)
'*************************CODE**************************
'requires a reference set for Microsoft DAO 3.x Object Library
Private Sub cmdFindAdd_Click()
On Error GoTo HandleError
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
'all three criteria required
'If any criteria is missing, say so and exit Sub
If Nz(Me.cmbDate, "") = "" Or Nz(Me.cmbLine, "") = "" Or Nz(Me.cmbShift,
"") = "" Then
MsgBox "parameters missing.! Enter all parameters"
Exit Sub
Else
Set db = CurrentDb()
'create SQL
strSQL = "SELECT lngLineId, lngShift, dtmDate FROM tblProductionDate"
strSQL = strSQL & " WHERE [lngLineId] = " & Me.cmbLine
strSQL = strSQL & " AND [lngShift] = " & Me.cmbShift
strSQL = strSQL & " AND [dtmDate] = #" & Me.cmbDate & "#;"
'open recordset
Set rs = db.OpenRecordset(strSQL)
'check for records
If rs.BOF And rs.EOF Then
MsgBox "No records found!!"
'open form in add mode
DoCmd.OpenForm "frmProdMain", , , , acFormAdd
Forms!frmProdMain.dtmDate = Me.cmbDate
Forms!frmProdMain.lngLine = Me.cmbLine
Forms!frmProdMain.lngShift = Me.cmbShift

'--- How many records for the criteria specified---
If rs.RecordCount = 1 Then
MsgBox rs.RecordCount & " record found"
Else
MsgBox rs.RecordCount & " records found"
End If
'------------------------
'open form to first record with [ponumber]
DoCmd.OpenForm "frmProdMain", , , "[ponumber] = " & Me.[ponumber]
End If
End If
HandleError_Exit:
On Error Resume Next
'clean up
rs.Close
Set rs = Nothing
Set db = Nothing
Exit Sub
HandleError:
MsgBox Err.Number & " - " & Err.Description
Resume HandleError_Exit
End Sub
'*************END CODE****************
:
Hi,
I have to make a entry form for people that are not tech savy.
The route I am taking is to use a dialog with selectable parameters on
it. When the user clicks the button, I want the form to search for
the criteria from a table. If the criteria matches, open entry form
with that record. If there is no match, then open the entry form and
automatically input the search parameters.
Still new at VBA and recordsets with DAO.
Here is the code for the button on the dialog so far:
*************************CODE**************************
Private Sub cmdFindAdd_Click()
Dim strSQL As String
Dim dtmDate As Date
Dim lngLine As Long
Dim lngShift As Long
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim blnFound As Boolean
Dim fldItem As DAO.Field
 
D

DeDBlanK

On May 7, 10:50 am, Steve Sanford <limbim53 at yahoo dot com> wrote:
Don't know what happened, but I am now having some really strange
stuff happening here.

Now for some reason the IDE is acting really strange. It corrects
things as I type and is not letting me see drop downs (the context
code) and is capitalizing things it shouldn't.

The code for the dialog is working, but if it found the record it just
opens a frmProdMain without any data (like it's loosing the ID for the
record)

Also when there isn't a record, the information is entering correctly,
but as soon as I move to the subform (frmProdMain2) it is taking the
parent form (frmProdMain) to a new record?

This is really frustrating me! Especially since it was working. I am
figuring something happened do the IDE.

Any suggestions?
Glad it is working.

--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)



DeDBlanK said:
On May 6, 6:56 pm, Steve Sanford <limbim53 at yahoo dot com> wrote:
Thank you again for all your help.  I really do appreciate it.
I figured out my issue, I'm such an idiot.
The whole error was due to me not typing the name correctly for the
field.
         Forms!frmProdMain.dtmDate = Me.txtDate
         Forms!frmProdMain.lngLineID = Me.cmbLine  <-This one
         Forms!frmProdMain.lngShift = Me.cmbShift
On my code for some reason I didn't type the Id at the end of
lngLineId.
Again I can't thank you enough.  I'm still a Noob when it come to VBA,
but the books are helping.
Thanks,
DeDBlanK
With the new info you provided, I made a table and a couple of forms. Since I
can't see the structure of your mdb (tables & forms), this might stillhave
errors.
First, from the main database window, select TOOLS/OPTIONS
Click on the "General" tab.
Uncheck both "Name Autocorrect" check boxes.
This is optional - Click on the FORMS/REPORTS
CHECK the "Always use event procedures"
Click OK
In the IDE, select TOOLS/OPTIONS
Every thing should be checked except the first check box "Auto syntax check"
Click OK
Paste in the following code. Then, in the menu bar, select DEBUG/COMPILE
Fix any errors.
'*******************CODE*************
Private Sub cmdFindAdd_Click()
   On Error GoTo HandleError
   Dim db As DAO.Database
   Dim rs As DAO.Recordset
   Dim strSQL As String
   'all three criteria required
   'If any criteria is missing, say so and exit Sub
   If Nz(Me.txtDate, "") = "" Or Nz(Me.cmbLine, "") = "" Or Nz(Me.cmbShift,
"") = "" Then
      MsgBox "parameters missing.! Enter all parameters"
      Exit Sub
   Else
      Set db = CurrentDb()
      'create SQL
      strSQL = "SELECT lngProdDateId FROM tblProductionDate"
      strSQL = strSQL & " WHERE [lngLineId] = " & Me.cmbLine
      strSQL = strSQL & " AND [lngShift] = " & Me.cmbShift
      strSQL = strSQL & " AND [dtmDate] = #" & Me.txtDate & "#;"
      'open recordset
      Set rs = db.OpenRecordset(strSQL)
      'check for records
      If rs.BOF And rs.EOF Then
         MsgBox "No records found!!"
         'open form in add mode
         DoCmd.OpenForm "frmProdMain", , , , acFormAdd
         Forms!frmProdMain.dtmDate = Me.txtDate
         Forms!frmProdMain.lngLineID = Me.cmbLine
         Forms!frmProdMain.lngShift = Me.cmbShift
      Else
         rs.MoveLast
         rs.MoveFirst
         '--- How many records for the criteria specified---
         If rs.RecordCount = 1 Then
            MsgBox rs.RecordCount & " record found"
         Else
            MsgBox rs.RecordCount & " records found"
         End If
         '------------------------
         'open form to first record with [ponumber]
         DoCmd.OpenForm "frmProdMain", , , "[lngProdDateId] = " &
rs!lngProdDateId
      End If
   End If
HandleError_Exit:
   On Error Resume Next
   'clean up
   rs.Close
   Set rs = Nothing
   Set db = Nothing
   'optional - close the form dlgFindAddReport
   DoCmd.Close acForm, Me.Name
   Exit Sub
HandleError:
   MsgBox Err.Number & " - " & Err.Description
   Resume HandleError_Exit
End Sub
'************************END CODE*************
This code compiles and run - for me - with my forms and table. Check field
and control names if you get errors. (and let me know  :)
I added these two lines to close the form "dlgFindAddReport"
   'optional - close the form dlgFindAddReport
   DoCmd.Close acForm, Me.Name
HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)
:
Ran the Code and I get an error
2465-Application-defined or object-defined error
It's happening at:
DoCmd.OpenForm "frmProdMain", , , , acFormAdd
         Forms!frmProdMain.dtmDate.Value = me.txtDate
         Forms!frmProdMain.lngLine.Value = me.cmbLine
         Forms!frmProdMain.lngShift.Value = me.cmbShift
I've tried using the long definition, Forms!dlgFindAddReport!txtDate
to no avail.
Also getting the same error number for a found record:
2465 - Access can't find the field '|" referred to in your expression
This is probably from the same thing I stated in my previous post
about not being bound to anything.
Sorry Double Post, but Read this one!!!!
Mr. Sanford,
Thank you for the code.  I actually started rewritting it and was
about to where you have it.
One thing that I don't know if I made apparent.  The dialog
(dlgFindAddReport) is actually an unbound form with combo boxes onit
with a giant button that run this code.  So calling anything other
than the combo boxes won't amount to much. My bad.
I had a couple of question on the code though:
For the check records, isn't possible to use
------------------------------------------------------------------
If rs.NoMatch then
     MsgBox "No Records Found!!"
Or is there a reason not to use NoMatch?
-------------------------------------------------------------------
Under the line for
'open form to first record with [ponumber]
        DoCmd.OpenForm "frmProdMain", , , "[ponumber] = " & Me.
[ponumber]
Where is the call out for the ponumber
(BTW, I didn't include this data, but it's actually [lngProdDateId]
which is the primary key for tblProductionDate which the frmProdMain
is bound to.)
That's where I am stuck now with the whole code.
I not quite sure how to pull the primary key from the recordset when
called from the strSQL, and then set that to the line where you have
the DoCmd.OpenForm "frmProdMain", , , "[ponumber] = " & Me.[ponumber]
Do I need just need to add the field into the strSQL for the
lngProdDateId?
-----------------------------------------------------------------------
Thanks,
DeDBlanK
On May 6, 11:59 am, Steve Sanford <limbim53 at yahoo dot com> wrote:
This is untested code.....
See if this helps you:
(watch for line wrap)
'*************************CODE**************************
'requires a reference set for Microsoft DAO 3.x Object Library
Private Sub cmdFindAdd_Click()
   On Error GoTo HandleError
   Dim db As DAO.Database
   Dim rs As DAO.Recordset
   Dim strSQL As String
   'all three criteria required
   'If any criteria is missing, say so and exit Sub
   If Nz(Me.cmbDate, "") = "" Or Nz(Me.cmbLine, "") = "" Or Nz(Me.cmbShift,
"") = "" Then
      MsgBox "parameters missing.! Enter all parameters"
      Exit Sub
   Else
      Set db = CurrentDb()
      'create SQL
      strSQL = "SELECT lngLineId, lngShift, dtmDate FROM tblProductionDate"
      strSQL = strSQL & " WHERE [lngLineId] = " & Me..cmbLine
      strSQL = strSQL & " AND [lngShift] = " & Me.cmbShift
      strSQL = strSQL & " AND [dtmDate] = #" & Me.cmbDate & "#;"
      'open recordset
      Set rs = db.OpenRecordset(strSQL)
      'check for records
      If rs.BOF And rs.EOF Then
         MsgBox "No records found!!"
         'open form in add mode
         DoCmd.OpenForm "frmProdMain", , , , acFormAdd
         Forms!frmProdMain.dtmDate = Me.cmbDate
         Forms!frmProdMain.lngLine = Me.cmbLine
         Forms!frmProdMain.lngShift = Me.cmbShift
      Else
         rs.MoveLast
         rs.MoveFirst
         '--- How many records for the criteria specified---
         If rs.RecordCount = 1 Then
            MsgBox rs.RecordCount & " record found"
         Else
            MsgBox rs.RecordCount & " records found"
         End If
         '------------------------
         'open form to first record with [ponumber]
         DoCmd.OpenForm "frmProdMain", , , "[ponumber] = " & Me.[ponumber]
      End If
   End If
HandleError_Exit:
   On Error Resume Next
   'clean up
   rs.Close
   Set rs = Nothing
   Set db = Nothing
   Exit Sub
HandleError:
   MsgBox Err.Number & " - " & Err.Description
   Resume HandleError_Exit
End Sub
'*************END CODE****************
HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)
:
Hi,
I have to make a entry form for people that are not tech savy.
The route I am taking is to use a dialog with selectable parameters

...

read more »- Hide quoted text -

- Show quoted text -
 
D

DeDBlanK

For the check records, isn't possible to use
Or is there a reason not to use NoMatch?
-------------------------------------------------------------------

If a recordset is opened without using a "Where" clause, all records are
returned. To find a specific record or records, you could use the .FindFirst
method. The NoMatch property is used to determine whether a Find/Seek
operation has succeeded.

If you use criteria (ie, a Where clause) when a recordset is opened, only
the records that match the criteria are returned. Opening a record does not
ahave a "NoMatch" property.
Under the line for
'open form to first record with [ponumber]
        DoCmd.OpenForm "frmProdMain", , , "[ponumber] = " & Me..
[ponumber]
Where is the call out for the ponumber
(BTW, I didn't include this data, but it's actually [lngProdDateId]
which is the primary key for tblProductionDate which the frmProdMain
is bound to.)

From your question, I didn't know your form names or field names, so I took
a guess.

Opening a recordset using "SELECT * FROM..." is slower and unneeded,
especially when the only field you need from the table is the PK.  So I would
use:

       strSQL = "SELECT lngProdDateId FROM tblProductionDate"
       strSQL = strSQL & " WHERE [lngLineId] = " & Me.cmbLine
       strSQL = strSQL & " AND [lngShift] = " & Me.cmbShift
       strSQL = strSQL & " AND [dtmDate] = #" & Me.cmbDate & "#;"
That's where I am stuck now with the whole code.
I not quite sure how to pull the primary key from the recordset when
called from the strSQL, and then set that to the line where you have
the DoCmd.OpenForm "frmProdMain", , , "[ponumber] = " & Me.[ponumber]

Try:

DoCmd.OpenForm "frmProdMain", , , "[lngProdDateId] = " & rs!lngProdDateId

HTH

Thought I had a problem, but I figured it out.
It was the way the lngProdDateId was called. Instead of filter I
wanted to use a OpenArg
DoCmd.OpenForm "frmProdMain", , , , acFormEdit, acWindowNormal,
"[lngProdDateId] = " & rs![lngProdDateId]

The IDE, don't know, but I followed your direction before and never
had one of the options check before and never scene it do what it was
doing.

Again, Steve thank you for all your help. People like you are what
make the internet wonderful (and access)
Can't say it enough THANKS!!!!!!
 
D

DeDBlanK

If a recordset is opened without using a "Where" clause, all records are
returned. To find a specific record or records, you could use the .FindFirst
method. The NoMatch property is used to determine whether a Find/Seek
operation has succeeded.
If you use criteria (ie, a Where clause) when a recordset is opened, only
the records that match the criteria are returned. Opening a record does not
ahave a "NoMatch" property.
Under the line for
'open form to first record with [ponumber]
        DoCmd.OpenForm "frmProdMain", , , "[ponumber] = " & Me.
[ponumber]
Where is the call out for the ponumber
(BTW, I didn't include this data, but it's actually [lngProdDateId]
which is the primary key for tblProductionDate which the frmProdMain
is bound to.)
From your question, I didn't know your form names or field names, so I took
a guess.
Opening a recordset using "SELECT * FROM..." is slower and unneeded,
especially when the only field you need from the table is the PK.  So I would
use:
       strSQL = "SELECT lngProdDateId FROM tblProductionDate"
       strSQL = strSQL & " WHERE [lngLineId] = " & Me.cmbLine
       strSQL = strSQL & " AND [lngShift] = " & Me.cmbShift
       strSQL = strSQL & " AND [dtmDate] = #" & Me.cmbDate &"#;"
That's where I am stuck now with the whole code.
I not quite sure how to pull the primary key from the recordset when
called from the strSQL, and then set that to the line where you have
the DoCmd.OpenForm "frmProdMain", , , "[ponumber] = " & Me.[ponumber]

DoCmd.OpenForm "frmProdMain", , , "[lngProdDateId] = " & rs!lngProdDateId

Thought I had a problem, but I figured it out.
It was the way the lngProdDateId was called.  Instead of filter I
wanted to use a OpenArg
DoCmd.OpenForm "frmProdMain", , , , acFormEdit, acWindowNormal,
"[lngProdDateId] = " & rs![lngProdDateId]

The IDE, don't know, but I followed your direction before and never
had one of the options check before and never scene it do what it was
doing.

Again, Steve thank you for all your help.  People like you are what
make the internet wonderful (and access)
Can't say it enough THANKS!!!!!!- Hide quoted text -

- Show quoted text -

Just when I thought I was safe....
Now I am having the dreaded remove filter on close.
Anyone know how to remove it. I am still searching threads trying to
find a solution.
 
D

DeDBlanK

On May 6, 2:56 pm, Steve Sanford <limbim53 at yahoo dot com> wrote:
For the check records, isn't possible to use
------------------------------------------------------------------
If rs.NoMatch then
     MsgBox "No Records Found!!"
Or is there a reason not to use NoMatch?
-------------------------------------------------------------------
If a recordset is opened without using a "Where" clause, all records are
returned. To find a specific record or records, you could use the .FindFirst
method. The NoMatch property is used to determine whether a Find/Seek
operation has succeeded.
If you use criteria (ie, a Where clause) when a recordset is opened, only
the records that match the criteria are returned. Opening a record does not
ahave a "NoMatch" property.
Under the line for
'open form to first record with [ponumber]
        DoCmd.OpenForm "frmProdMain", , , "[ponumber] = " & Me.
[ponumber]
Where is the call out for the ponumber
(BTW, I didn't include this data, but it's actually [lngProdDateId]
which is the primary key for tblProductionDate which the frmProdMain
is bound to.)
From your question, I didn't know your form names or field names, so Itook
a guess.
Opening a recordset using "SELECT * FROM..." is slower and unneeded,
especially when the only field you need from the table is the PK.  So I would
use:
       strSQL = "SELECT lngProdDateId FROM tblProductionDate"
       strSQL = strSQL & " WHERE [lngLineId] = " & Me.cmbLine
       strSQL = strSQL & " AND [lngShift] = " & Me.cmbShift
       strSQL = strSQL & " AND [dtmDate] = #" & Me.cmbDate& "#;"
That's where I am stuck now with the whole code.
I not quite sure how to pull the primary key from the recordset when
called from the strSQL, and then set that to the line where you have
the DoCmd.OpenForm "frmProdMain", , , "[ponumber] = " & Me.[ponumber]
Try:
DoCmd.OpenForm "frmProdMain", , , "[lngProdDateId] = " & rs!lngProdDateId
HTH
Thought I had a problem, but I figured it out.
It was the way the lngProdDateId was called.  Instead of filter I
wanted to use a OpenArg
DoCmd.OpenForm "frmProdMain", , , , acFormEdit, acWindowNormal,
"[lngProdDateId] = " & rs![lngProdDateId]
The IDE, don't know, but I followed your direction before and never
had one of the options check before and never scene it do what it was
doing.
Again, Steve thank you for all your help.  People like you are what
make the internet wonderful (and access)
Can't say it enough THANKS!!!!!!- Hide quoted text -
- Show quoted text -

Just when I thought I was safe....
Now I am having the dreaded remove filter on close.
Anyone know how to remove it.  I am still searching threads trying to
find a solution.- Hide quoted text -

- Show quoted text -

Make shift solution here (http://groups.google.com/group/
microsoft.public.access.formscoding/browse_thread/thread/
289dfb5ee71cad2d/06085e99fcf258d7?hl=en&lnk=gst&q=remove+filter+on
+close#06085e99fcf258d7)
But I would really like to get the filter working.
 
S

Steve Sanford

What code do you have in the Open event of the form "frmProdMain"?

Have you tried

Me.FilterOn = False

in the form Close event?


HTH
 
D

DeDBlanK

What code do you have in the Open event of the form "frmProdMain"?

Have you tried

 Me.FilterOn = False

in the form Close event?

HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)






- Show quoted text -

Sorry, been out of office. Yes. OnClose Me.Filter = False does not
work. I ended up just using the way I had it. I think I can just
change the form to DataEntry = True and that should resolve some of my
issues for the entry portion. Just have to figure out the edit
portion of the form. What I have now should work.
If I do find another solution, I'll be sure to post it to this thread.
Thanks again.
 
S

Steve Sanford

You have Me.Filter = False . This is wrong

It is Me.FilterOn = False

Note the difference..... Me.FilterON = False


I've kind of lost where you are at with the problem. You have a form with
three text boxes for criteria. Someone enters the required info into the
boxes, then clicks on a button. The code opens a recordset and if records are
found, opens a form to the first record that matches the PK (lngProdDateId).
If no records are found, the same forms opens in Add Mode, pre-filling text
boxes with the info from the search text boxes.

No filters are used. Am I right so far??

If there is a filter you can't get rid of: To remove an unwanted filter, to
open the form in design view, delete anything in the filter property, save
the form and then close the form. It has to be in that order.


HTH
 
D

DeDBlanK

You have   Me.Filter = False .  This is wrong

It is          Me.FilterOn = False

Note the difference.....  Me.FilterON = False

I've kind of lost where you are at with the problem. You have a form with
three text boxes for criteria. Someone enters the required info into the
boxes, then clicks on a button. The code opens a recordset and if records are
found, opens a form to the first record that matches the PK (lngProdDateId).
If no records are found, the same forms opens in Add Mode, pre-filling text
boxes with the info from the search text boxes.

No filters are used.  Am I right so far??

If there is a filter you can't get rid of:  To remove an unwanted filter, to
open the form in design view, delete anything in the filter property, save
the form and then close the form. It has to be in that order.

HTH
--
Steve S
--------------------------------
"Veni, Vidi, Velcro"
(I came; I saw; I stuck around.)






- Show quoted text -

Sorry for the delay Steve, been on vacation and outragously busy.
To answer your question, You are right so far with that version off
code. I fixed that error a while ago and still had issues which
brought me to another solution.
I disabled the required parameters in the form that the user enters on
the prompt.
This way the form can not be saved if moved to another record. Still
doesn't prevent moving to another record, but I was mainly concerned
with data just be spat all over the place.
I have been trying to get this data to calculate OEE, wouldn't happen
to know an easy way to do this?
Also if you happen to know or point me in a direction of a good way of
accessing the tables, queries, ect. through HTML that would be great
too!
Again, thanks for all your help. I really do appreciate it.
Have a great day,
DeDBlanK
 

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

Top