click button running multiple functions (1 Viewer)

JahJr

Andy
Local time
Yesterday, 20:46
Joined
Dec 3, 2008
Messages
93
I have the following code and it will work independent of each other. How do I combine it so it records the information, closes 1 Form and opens another form? I appologize but I am a idiot when it comes to VB.

Private Sub LogBet_Click()
On Error GoTo Err_LogBet_Click

DoCmd.GoToRecord , , acNewRec
Exit_LogBet_Click:
Exit Sub
Err_LogBet_Click:
MsgBox Err.Description
Resume Exit_LogBet_Click

End Sub

Private Sub LogBet_Click()
On Error GoTo LogBet_Click_Err
DoCmd.Close acForm, "Line"
DoCmd.OpenForm "HPSB Home Screen", acNormal, "", "", , acNormal

LogBet_Click_Exit:
Exit Sub
LogBet_Click_Err:
MsgBox Error$
Resume Home_Click_Exit
End Sub
 

CyberLynx

Stuck On My Opinions
Local time
Yesterday, 18:46
Joined
Jan 31, 2008
Messages
585
I'm not sure in which Form Code Module your sub procedure resides in but if your intent is to go to a new Record in the Form name Line, have the User fill the record then Close the Form named Line and open the Form named HPSB Home Screen then you can't since the Form Line will be closed right away as soon as the Form sets up for new record.

What exactly is the intent of:

DoCmd.GoToRecord , , acNewRec

Are you doing this to so as to Save the previous record entered? If so you would be better off to use:

DoCmd.Runcommand acCmdSaveRecord

In any case....to combine the two is:

Code:
Private Sub LogBet_Click()
   On Error GoTo Err_LogBet_Click

   DoCmd.GoToRecord , , acNewRec
   DoCmd.Close acForm, "Line"
   DoCmd.OpenForm "HPSB Home Screen"

Exit_LogBet_Click:
   Exit Sub

Err_LogBet_Click:
   MsgBox Err.Number & " -- " & Err.Description
   Resume Exit_LogBet_Click
End Sub

If your intent is as mentioned above then you will need Two Buttons.

.
 

JahJr

Andy
Local time
Yesterday, 20:46
Joined
Dec 3, 2008
Messages
93
Thank you for your help. The code did what i was trying to acccompolish but I still have this problem that when it records all the information to the table it writes over the previous record. I think this has to do with using the control source feature in my combo boxes. Do you know a way around this? When this information gets logged into the table it needs to be where you cant write over it.
 

CyberLynx

Stuck On My Opinions
Local time
Yesterday, 18:46
Joined
Jan 31, 2008
Messages
585
To answer your question......No.

I don't have a clue what situation you have there nor am I sure of exactly what you are trying to do. I can only assume at this point and to be honest that is sketchy at best.

Is this for a Audit Log of some sort? History?

What exactly are you trying to accomplish?

.
 

JahJr

Andy
Local time
Yesterday, 20:46
Joined
Dec 3, 2008
Messages
93
On the Form ther are 3 combo boxes.
1. Select Customer #
2. Select Sport (NCAA Football, NFL, NCAA Basketball, NBA)
3. Select Team

Then there is a text box where you enter the line.

Now click Log Bet.

I am trying to keep up with all the bets placed. This information should go to a Table LoggedBets.
 

wiremonkey22

Registered User.
Local time
Yesterday, 18:46
Joined
Jan 13, 2008
Messages
68
I'm not sure why it would be writing over previous data unless you are doing it have you tried an on load or open event so that you don't change your own data. :confused:

Private Sub Form_Load()
DoCmd.GoToRecord , , acNewRec
End Sub

The only other thing i can think of is make sure your field control source's are storing the data in the table (they don't say Unbound)
 

JahJr

Andy
Local time
Yesterday, 20:46
Joined
Dec 3, 2008
Messages
93
No i have not tried a on load event but i think that would take care of it. I tried playing with the code that you posted but it would not work. If I could just get the form when it opens to default all of the combo boxes to the new record instead of the last record i think that would fix it. If you can help me with the on load event I would appreciate it.
 

wiremonkey22

Registered User.
Local time
Yesterday, 18:46
Joined
Jan 13, 2008
Messages
68
The on load event should bring up a new record every time the form opens
what is it doing when you close and open it back up?

also

go to design view right click on your combo boxes-properties-check the control source. Are you storing the value of the combo box in the field of the table if not click the arrow and select the field you want to store it in.
 

Users who are viewing this thread

Top Bottom