This is probably one of the stupidest questions to ask but i am lost. this is my delema. I have never made a form that grabs data from a table without actually using the recordset property on the form. I am trying to move up a level by having an unbound text box and grabbing the record I need from that and then populating my form from the data in that certain record. I just don't like the fact that when you pull up a form that uses the recordset property you are pulling up the first record in the table. It just doesn't look very professional to me. The problem that i am having is that i am not too familiar with recordset coding. i looked all around the forum for what i need but can't get it to work.
here is my code for my after update of my text box "txtpartnum"
'Find the record that matches the control.
Dim rs As DAO.Recordset
Dim db As DAO.Database
If partnum.Value <> "" Then
Set db = Application.CurrentDb
Set rs = db.OpenRecordset("labels") 'my table is called labels
rs.FindFirst "[PartNumber] = '" & Me![txtpartnum] & "'" 'partnumber is my PK field in my labels table
Me.Bookmark = rs.Bookmark
If rs.NoMatch Then
Dim msg, style, varchoice
msg = "This record does not exist. Do you want to Make a new record?"
style = vbYesNo
varchoice = MsgBox(msg, style)
If varchoice = vbYes Then
DoCmd.GoToRecord , , acNewRec
txtpart.Value = txtpartnum.Value
Me.Refresh
txtdata.SetFocus
Else
Combo33.Value = txtpart.Value
End If
End If
Else
Exit Sub
End If
I know this is probably so off so please let me know
p.s. i haven't even gotten around to populate the fields on the form. once the record is found. i figured i should do this in baby steps.
Thank you
Sean
here is my code for my after update of my text box "txtpartnum"
'Find the record that matches the control.
Dim rs As DAO.Recordset
Dim db As DAO.Database
If partnum.Value <> "" Then
Set db = Application.CurrentDb
Set rs = db.OpenRecordset("labels") 'my table is called labels
rs.FindFirst "[PartNumber] = '" & Me![txtpartnum] & "'" 'partnumber is my PK field in my labels table
Me.Bookmark = rs.Bookmark
If rs.NoMatch Then
Dim msg, style, varchoice
msg = "This record does not exist. Do you want to Make a new record?"
style = vbYesNo
varchoice = MsgBox(msg, style)
If varchoice = vbYes Then
DoCmd.GoToRecord , , acNewRec
txtpart.Value = txtpartnum.Value
Me.Refresh
txtdata.SetFocus
Else
Combo33.Value = txtpart.Value
End If
End If
Else
Exit Sub
End If
I know this is probably so off so please let me know
p.s. i haven't even gotten around to populate the fields on the form. once the record is found. i figured i should do this in baby steps.
Thank you
Sean